开发者

Javascript unset array

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜