views:

632

answers:

5

How do i unset an array in javascript? i just want to empty it - so it has nothing in it keys or anything

+1  A: 

Assign an empty array to it

   x = []
stereofrog
+1  A: 

you can assign a new array to it:

var oldArray =["element1","element2","element3"];
...
oldArray = new Array();
marcos
A: 
var array = ["elem", "item"];
...
array = []; // Empty!
Björn
+1  A: 
array.length = 0

should work.

pms1969
+1  A: 

What about delete?

delete array

Or to delete a single index:

delete array[x]
James Brooks