Removing all elements of an array in JavaScript

 <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(scripts.join(","));
document.write("<br>--Now after emptying --<br>");
scripts.length=0; // Emptying all elements
document.write(scripts.join(","));
</script>
Output
PHP,ASP,JavaScript,HTML,SQL
--Now after emptying --
We can read the number of elements in an array by using length property and here we have set the length to zero.

By re-declaring the array to new variable.

scripts = [];
or
var scripts = new Array();
Array Reference Removing elements from End of Array Removing elements from any position of an array
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com










    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer