Javascript Reset

How to disable array in javascript? I just want to empty her - so he has nothing in the keys or something like that

+7
javascript arrays unset
source share
6 answers

you can assign it a new array:

var array = ["element1","element2","element3"]; ... array = new Array(); 

OR

 array = []; 
+9
source share

Assign it an empty array

  x = [] 
+6
source share

How about removal?

 delete array 

Or delete one index:

 delete array[x] 
+3
source share
 array.length = 0 

must work.

+2
source share
 var array = ["elem", "item"]; ... array = []; // Empty! 
+1
source share

STATEMENT (I know his old and answered)


If you want to clear the array, it already was. If you want to disconnect an array, you can assign an undefined variable ...

 var undef; var myArr = []; ... myArr = undef; // typeof myArr == undefined 
0
source share

All Articles