Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The pop() method of Array instances removes the last element from an array and returns that element. This method changes the length of the array.
None.
The removed element from the array; undefined if the array is empty.
The pop() method removes the last element from an array and returns that value to the caller. If you call pop() on an empty array, it returns undefined.
Array.prototype.shift() has similar behavior to pop(), but applied to the first element in an array.
The pop() method is a mutating method. It changes the length and the content of this. In case you want the value of this to be the same, but return a new array with the last element removed, you can use arr.slice(0, -1) instead.
The pop() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable.
The following code creates the myFish array containing four elements, then removes its last element.
The pop() method reads the length property of this. If the normalized length is 0, length is set to 0 again (whereas it may be negative or undefined before). Otherwise, the property at length - 1 is returned and deleted.
push and pop are intentionally generic, and we can use that to our advantage — as the following example shows.
Note that in this example, we don't create an array to store a collection of objects. Instead, we store the collection on the object itself and use call on Array.prototype.push and Array.prototype.pop to trick those methods into thinking we're dealing with an array.
| ECMAScript® 2027 Language Specification # sec-array.prototype.pop |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.