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

|