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("<br>--Now after emptying --<br>");
scripts.length=0; // Emptying all elements
--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 = [];
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


* indicates required
Subscribe to plus2net

    Post your comments , suggestion , error , requirements etc here

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