Home Java Javascript-array JavaScript Array unshift
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

JavaScript Array unshift

Advertisement
In this Tutorial we want to describe you a code that helps you in understanding JavaScript Array unshift.

JavaScript Array unshift

     

In this Tutorial we want to describe you a code that helps you in understanding JavaScript Array unshift.The code declare an  array variable instantiate  array object, this object hold the element. The for loop run the script till variable i is less than array length. The document. write print the element in an array before applying unshift method.

array.unshift ( AA,BB) - This method  add  elements to the beginning of an array and returns you  the new length.

Similarly this method add element AA,BB to the beginning of an array object elements.

Again, the for loop run the script till the variable i is less than the array length. The document. write return you an array after applying unshift method.

JavaScriptArrayUnshift.html

<html>
  <head>
  <title>JavaScript Array unshift</title>
  <h1>JavaScript Array unshift</h1>
  <hr></hr>
  <script language="javascript" type="text/javascript">
  var array=new Array();
  array[0]="Rose";
  array[1]="India";
  array[2]=".net";
  array[3]="Rohini";
  document.write("<b>"+"Array before applying unshift method: "+"</b>"+"<br>");
  for(i=0;i<array.length;i++){
  document.write(array[i]+"<br>");
  }
  </script>  <hr></hr> 
  <script> 
  array.unshift("AA","BB");
  document.write("<b>"+"Array after applying unshift method: "+"</b>"+"<br>");
  for(i=0;i<array.length;i++){
  document.write(array[i]+"<br>");
  }
  </script> 
  </head>
  <body>
     </body>
</html>

Output of the program

Download source code

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 13, 2008

Related Tutorials

Ask Questions?    Discuss: JavaScript Array unshift  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com