+ 1

Which is not a correct way to empty an array?

let arr = [2, 4, 6, 12]; A. arr = []; B. arr.length = 0; C. arr.splice(0, arr.length); D. While(arr.length > 0) { arr.push();}

25th Apr 2023, 1:55 AM
gunalan
gunalan - avatar
2 Answers
+ 4
Like Kaminorsabir Kamin said, it is an infinite loop. You are adding elements to the array. So the array length always will be > 0.
25th Apr 2023, 7:26 AM
Ugulberto SĂĄnchez
Ugulberto SĂĄnchez - avatar
+ 3
D. is Infinite loop
25th Apr 2023, 2:13 AM
Kaminorsabir Kamin
Kaminorsabir Kamin - avatar