Home Java Javascript-array JavaScript array pop



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

Related Tags for JavaScript array pop:
javajavascriptcarrayscriptobjectmethodremoveipreturnintelementmoveelementsexamplepushaddtoexamastshboteilitlastlscanpopimfrominasmntcaddjadesembottommeintoobjsimilarxaxampsurnsoeeathamplrayandarsimvattscrssriripthavsthatlsojepleplmovmindonomo


More Tutorials from this section

Ask Questions?    Discuss: JavaScript array pop  

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.