vote up 0 vote down star

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

flag

5 Answers

vote up 1 vote down

Assign an empty array to it

   x = []
link|flag
vote up 1 vote down

you can assign a new array to it:

var oldArray =["element1","element2","element3"];
...
oldArray = new Array();
link|flag
vote up 1 vote down
array.length = 0

should work.

link|flag
vote up 0 vote down
var array = ["elem", "item"];
...
array = []; // Empty!
link|flag
vote up 0 vote down

What about delete?

delete array

Or to delete a single index:

delete array[x]
link|flag

Your Answer

Get an OpenID
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.