Home Java Javascript-array JavaScript array push



JavaScript array push
Posted on: November 5, 2008 at 12:00 AM
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

Related Tags for JavaScript array push:
javajavascriptcarrayscriptobjectcontrolobjectsmethodsmultiplemethodvariableipvalueintriathisreverseforexamplepushvaluestocilexamstoresinglecisheilitdesmulticanlivaruseulpopmaninasmntouttrcajesmeintoobjdescribetorxawhichxampstipsusoatisirhallmplrayandarcodcoderollingvascrssriripthavstabablatialuctsetcetclatinipljepleplndodsodeonomolo


More Tutorials from this section

Ask Questions?    Discuss: JavaScript array push  

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.