JavaScript Array Clear

This page discusses - JavaScript Array Clear

JavaScript Array Clear

In this tutorial you will learn how to use the clear method in your JavaScript program.

Clear() method is used to clear all the defined array. In this section, you will study how to clear the Array in JavaScript. You can see in the given example, we have create an instance of array which consists of elements 'Hello' and 'World'. Then we have used the clear() method which removes all elements from an Array instance. After removing the array by clear() method, the resulting array's length will become zero.

Here is the code:

<h2> Array Clear Example</h2>
var array=new Array();
document.write("<b>Array is: </b> <br> ")
for (var i = 0; i < array.length; i++){
document.write(array[i] + "<BR>");
document.write("<b>Now the Array is:</b> <br><br>");
for (var i = 0; i < array.length; i++) {
document.write(array[i]+ "<BR>");
<b>[After using the clear() method, the array is removed.]</b>
<body bgcolor="lightBlue"/>

Output will be displayed as:

Download Source Code

Share on Google+Share on Google+

JavaScript Array Clear

Posted on: April 17, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JavaScript Array Clear  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image