tags:

views:

705

answers:

2

Hi, if there is an array, is it possible to empty with .remove()

for instance if

   A = [1,2,3,4];

how can I empty that.

thanks

+7  A: 

Very simple:

A = [];
Philippe Leybaert
Hi, I have a few arrays and everytime I run it, it adds a few items to it, I initialize at the start of the code but it still keeps its value and add more values to it,do I need to clear the array after the code is run too?
amir
use var inside your functions. google that.
Makram Saleh
+8  A: 

If you need to keep the original array because you have other references to it that should be updated too, you can clear it without creating a new array by setting it's length to zero:

A.length = 0;
Matthew Crumley