Home Java Javascript-array JavaScript Array Clear



JavaScript Array Clear
Posted on: November 10, 2008 at 12:00 AM
Clear() method is used to clear all the defined array. In this section, you will study how to clear the Array in JavaScript.

JavaScript Array Clear

     

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:

<html>
<head>
<h2> Array Clear Example</h2>
<script>
var array=new Array();
array[0]="Hello";
array[1]="World";
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>");
array.clear();
for (var i = 0; i < array.length; i++) {
document.write(array[i]+ "<BR>");
}
</script>
<b>[After using the clear() method, the array is removed.]</b>
</head>
<body bgcolor="lightBlue"/>
</html>

Output will be displayed as:

Download Source Code

Related Tags for JavaScript Array Clear:
javajavascriptccomarrayscriptiomethodsedremoveipviinstancethisnsislengthelementcreatemoveelementsdefineexamplestudycleartoexamldeareilzerosectioncanuseulresultfromceinasstamntcajafterclesstsemallmehowdefinedxawhichxampssueeatmovingishellohallivmplrayeaandarconsremovingvinvazscrssriripthavstafhellofinpleplmovndonomo


More Tutorials from this section

Ask Questions?    Discuss: JavaScript Array Clear  

Post your Comment


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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.