pop()

The pop() method is used to delete the last list item of an array from the array. The returned value is the new last value of the array.

syntax:

arrayName.pop()

EXAMPLE

var newArray = new Array(10, 20);



document.write("The contents of the array are : " + newArray[0] + " and " + newArray[1] + "
");



newArray.pop()



document.write("The contents of the array are now : " + newArray[0] + " and " + newArray[1] );

The example starts with the creation of an array called newArray which contains the numbers 10 and 20. The document.write statement writes some applicable text to the screen along with the array contents. The array is then popped with the pop() method, deleting the last item of the array. The next document.write statement then writes the contents of the array to the screen, showing that the last item has been deleted due to the "undefined" return value from the now non-existant second value of the array. The output looks as follows:



The contents of the array are : 10 and 20

The contents of the array are now : 10 and undefined