How can you quickly remove all elements from an array that has already been declared previously?
$ arr = null;
removes the array itself, not its contents.
Answer 1, authority 100%
Maybe I didn’t understand something, but:
var array = [1,2,3,4,5];
array = []; //: D
Answer 2, authority 99%
arr.splice (0, arr.length);
or
arr.length = 0;
Answer 3, authority 29%
I’m just getting started with JS , and I myself came across this forum in search of an answer to the question posed.
It seems like I found it in the arr.shift ();
method. This method clears the 0 array cell.
You can make a loop for clearing an array, for example, or maybe there are more efficient ways.