Removing all elements of an array in JavaScript

Emptying an array is a common requirement in a JavaScript to compile new data. We can achieve this by different ways.

Removing all elements by making length zero.

We care read the number of elements in an array by using length property and we can set the length to zero. Here it is used to empty the array.
 <script type="text/javascript">
var scripts = new Array();
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";
scripts[4] = "SQL";
document.write("<br>--Now after emptying --<br>");
scripts.length=0; // Emptying all elements

By re-declaring the array to new variable.

scripts = [];
var scripts = new Array();
Your Rating

Post your comments , suggestion , error , requirements etc here .

HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 All rights reserved worldwide Privacy Policy Disclaimer