[an error occurred while processing this directive]

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:




<title>JavaScript array pop example</title>
<script type="text/javascript">
var arr=new Array(5);
document.write("Array arr contains(Before pop())="+arr+"</br>");
document.write("Array arr contains(After pop()) ="+arr+"</br>");
<h2>Example of array pop() method</h2>
Poped last two elements of array "arr" 

Output of this example is as follows:

Download Source Code


[an error occurred while processing this directive]