How to Remove All Elements From a JavaScript Array

To remove all the elements from a JavaScript array, simply set the array length to 0, as shown in the following example:

var aryTest = [1,2,3,4];
document.write(aryTest.length);

aryTest.length = 0;
document.write(aryTest.length);

Related articles:
JavaScript Arrays Summary and Reference
JavaScript Array length Property

Leave a Reply