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



Home Java Javascript-array JavaScript array pop

Related Tutorials


 
 

Share on Google+Share on Google+

JavaScript array pop

Advertisement
As in our example of JavaScript array push we can see that push() method adds one or more elements into the JavaScript array similarly.

JavaScript array pop

     

As in our example of JavaScript array push we can see that push() method adds one or more elements into the JavaScript array similarly the JavaScript's array object pop() method removes an element from the bottom of the array and it also returns the last element of the array.

Here in this example of JavaScript array pop method we have created an array of the length 5 and then added five elements into this array. After this we have used the pop() method onto the array object and have removed two elements from this now the array contains only three elements. Here is the full example code of this example as follows:

 

 

 

<html>
<head>
<title>JavaScript array pop example</title>
<script type="text/javascript">
var arr=new Array(5);
arr[0]="Rose";
arr[1]="India";
arr[2]="Technologies";
arr[3]="Pvt";
arr[4]="Ltd";
document.write("Array arr contains(Before pop())="+arr+"</br>");
arr.pop();
arr.pop();
document.write("Array arr contains(After pop()) ="+arr+"</br>");
</script>
</head>
<body>
<h2>Example of array pop() method</h2>
Poped last two elements of array "arr" 
</body>
</html>

Output of this example is as follows:

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 pop  

Post your Comment


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