On Jan 18, 10:36 am, timothytoe <timothy...@gmail.comwrote:
I can think of several easy ways to clear out an array. The most
obvious:
arr=[];
This doesn't "clear out" the array. This changes the array to which
the "arr" variable points. If two variables point to the array to be
cleared out then this won't work
var a = [0,1,2];
var b = a;
a = [];
console.log(a) // []
console.log(b) // [0,1,2]
arr.length=0;
This seems like a good option if the objective is to really clear out
the array.
arr=null;
same problem as the first option
What do most JavaScript programmers expect to see?
It depends what your goal is, exactly.
Since JS is
transmitted, do I typically just standardize on the most compact form?
Size is only one constraint. Correct and fast execution are important
too.
Peter