开发者

Javascript unset array

开发者 https://www.devze.com 2022-12-24 03:41 出处:网络
How do i unset an array in javascript? i just want to empty it - so it has nothing 开发者_开发技巧in it keys or anythingyou can assign a new array to it:

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

精彩评论

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