JavaScript (ES2026) reference · Array Methods
JavaScript Array pop() Method
Remove the last element from the array and return it. Changes the array; returns undefined if it is empty.
JavaScript (ES2026) Since ES3
Syntax
array.pop()
Return value
The removed element, or undefined.
Examples
const stack = [1, 2, 3];
console.log(stack.pop(), stack);
Output
3 [ 1, 2 ]
const history = ["home", "about", "contact"];
while (history.length) console.log("back from", history.pop());
Output
back from contact back from about back from home
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
In other languages
list.pop()· Python
Related
array.push()· Add one or more elements to the end of the array and return the new length. Changes the array in place.array.shift()· Remove the first element of the array and return it, moving the other elements down. Returns undefined if empty.array.splice()· Remove, replace or insert elements at a position, changing the array in place. Returns the removed elements.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial