Programmer's Wiki
Advertisement

Removes the last item in an array and returns it.

function array_pop(arr) {
	var pop = arr.pop();
	return pop;
}

Example Javascript Usage[]

arr = new Array('dog', 'cat', 'lion', 'tiger', 'bear');
var lastitem = array_pop(arr);
alert (lastitem); /* Gives:  bear  */ 
document.write(arr); /* Gives:  dog,cat,lion,tiger  */
Advertisement