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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array.pop()

Return value

The removed element, or undefined.

Examples

Remove the last elementTry it yourself
const stack = [1, 2, 3];
console.log(stack.pop(), stack);

Output

3 [ 1, 2 ]
Use an array as a stackTry it yourself
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

VersionChange
JavaScript ES3Added

In other languages

Was this page helpful?