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!
How can I remove all items and just leave an empty array? And is it a good idea to use this?
Thank you very much! |
|||||
|
If there are no other references to that array, then just create a new empty array over top of the old one:
If you need to modify an existing array—if, for instance, there's a reference to that array stored elsewhere:
|
|||
|
one of those two:
|
|||||||||||||||
|
Using |
|||
|
While you can set it to a new array like some of the other answers, I prefer to use the clear() method as such:
|
|||
|
The following article should answer part 2. http://stackoverflow.com/questions/864516/what-is-javascript-garbage-collection |
|||
|
Out of box idea:
|
|||
|