JavaScript Array: 4 ways to empty

For example we have following array;

var arrAlphas = [1,2,3,4,5];


Set to empty array reference

arrAlphas = [];

Sets to new reference, old instance remains intact


Set the length to zero

arrAlphas.length = 0;


splice function

arrAlphas.splice(0, arrAlphas.length);


pop function

while(arrAlphas.length){
  arrAlphas.pop();
}
Posted Status in Programming
Login InOR Register