Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Javascript-array JavaScript array push

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript array push

Advertisement
In JavaScript we can use the Array Object which has the facility to store multiple values into a single variable.

JavaScript array push

     

In JavaScript we can use the Array Object which has the facility to store multiple values into a single variable. For manipulating array objects and controlling their values we have some methods such as push(), pop(), reverse() etc. Here in this example code we have described about the JavaScript's array object push() method.

We can add the elements into the array object with the use of push() method. push() method adds one or more elements to the array object and also returns the new length of the array.

In our example of JavaScript array push we have created a JavaScript array object "arr" and it contains two elements "Rose" and "India" and we have added one more element into it by using the method push(). Here is the full example code and its output of our example :

 

 

<html>
<head>
<title>JavaScript array push example</title>
<script type="text/javascript">
var arr=new Array(2);
arr[0]="Rose";
arr[1]="India";
document.write("Array arr contains(Before push())="+arr+"</br>");
arr.push("Technologies");
document.write("Array arr contains(After push()) ="+arr+"</br>");
</script>
</head>
<body>
<h2>Example of array's push() </h2>
Push method insert the new element at the end of array
</body>
</html>

Output :

Download Source Code

Advertisements

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 5, 2008

Related Tutorials

Discuss: JavaScript array push  

Post your Comment


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