CKTIS / JavaScript
Array.prototype.pop: removing the last element
pop removes the last position, shortens length, and returns its value or undefined for an empty array.
Version: ECMAScript 2026 draft; example target: Node.js 24.22.2
Syntax
array.pop()array.pop() reads the value at index length - 1, deletes that property, sets length to length - 1, and returns the value. For zero length it returns undefined and sets length to 0. If the last position is a sparse hole, it also returns undefined but still shortens the array.
The method mutates its receiver and is generic for mutable array-like objects. It accepts no arguments. A null or undefined receiver throws TypeError. Deleting a non-configurable property, writing a read-only length, or a Proxy trap can throw; earlier effects of the algorithm need not be rolled back. The example demonstrates an ordinary stack, a hole, and use on an array-like object.
Examples
const stack = ["a", "b"];
console.log(stack.pop(), stack.join(","), stack.length);
const sparse = [1, ,];
console.log(sparse.pop(), sparse.length, 1 in sparse);
const record = { 0: "x", 1: "y", length: 2 };
console.log(Array.prototype.pop.call(record), record.length, 0 in record, 1 in record);Result
b a 1 undefined 1 false y 1 true false