var arr = [-3, -34, 1, 32, -100];
How can I remove all items and just leave an empty array?
And is it a good idea to use this?
arr = [];
Thank you very much!
var arr = [-3, -34, 1, 32, -100];
How can I remove all items and just leave an empty array?
And is it a good idea to use this?
arr = [];
Thank you very much!
Using arr = [];
to empty the array is far more efficient than doing something like looping and unsetting each key, or unsetting and then recreating the object.
While you can set it to a new array like some of the other answers, I prefer to use the clear() method as such:
array.clear();
The following article should answer part 2. http://stackoverflow.com/questions/864516/what-is-javascript-garbage-collection