Title here

4 ways to empty an array in JavaScript

For example we have following array;
var arrAlphas = [1,2,3,4,5];

Method 1:
arrAlphas = []; //sets to new reference, old instance remains intact

Method 2
arrAlphas.length = 0;

Method 3:
arrAlphas.splice(0, arrAlphas.length);

Method 4:
while(arrAlphas.length){
arrAlphas.pop();
}

Posted Status in Programming
Recommended