How do i unset an array in javascript? i just want to empty it - so it has nothing 开发者_开发技巧in it keys or anything
you can assign a new array to it:
var array = ["element1","element2","element3"];
...
array = new Array();
OR
array = [];
Assign an empty array to it
x = []
array.length = 0
should work.
What about delete?
delete array
Or to delete a single index:
delete array[x]
var array = ["elem", "item"];
...
array = []; // Empty!
FOR REFERENCE (I know its old and answered)
If you want to empty the array, that has been answered already. If you want to unset the array, you could assign an unset variable...
var undef;
var myArr = [];
...
myArr = undef;
// typeof myArr == undefined
精彩评论