JavaScript Array pop() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.pop() removes the last element, shortens length by one, and returns that element. It mutates the array in place — the opposite end of push().

Remember
array.pop()

removes last element
returns that element
empty [] → undefined

mutates array · length decreases
pair with push() → LIFO stack

Syntax

Call array.pop. Start with this line.

JavaScript
array.pop()
CallWhat it does
array.pop()Primary signature.
array.pop(...)Call with the arguments your case needs.

Built into JavaScript. Call pop(...) on an array instance — no import required.

Library declarations
JavaScript
array.pop()

Parameters

ParameterDescription
ArrayRequired. Target to shorten

Return Value

Return ValueDescription
*Removed element, or undefined

JavaScript Examples

Example 1 — Remove the Last Element

Pop "yellow" from a color list and keep the rest.

JavaScript
const colors = ["red", "green", "blue", "yellow"];

const removed = colors.pop();

console.log(removed);
// "yellow"
console.log(colors);
// ["red", "green", "blue"]
Try It Yourself

How It Works

  1. Start with four colors. Last index is "yellow".
  2. Call pop(). That last value is removed and returned.
  3. Capture the return. removed holds "yellow".
  4. Array shrinks. colors now has three items — mutated in place.

Example 2 — Empty Array Returns undefined

Popping [] does not throw — you get undefined.

JavaScript
const empty = [];

const result = empty.pop();

console.log(result);
// undefined
console.log(empty.length);
// 0
Try It Yourself

How It Works

  1. No elements to remove. Length is already 0.
  2. Return is undefined. Same as reading a missing slot.
  3. Array stays empty. Length remains 0.
  4. Guard when needed. Check arr.length if empty should be an error.

Example 3 — Stack with push() and pop()

Last item pushed is the first one popped (LIFO).

JavaScript
const stack = [];

stack.push("first");
stack.push("second");
stack.push("third");

console.log(stack.pop()); // "third"
console.log(stack.pop()); // "second"
console.log(stack);
// ["first"]
Try It Yourself

How It Works

  1. Push builds the stack. Items land at the end: first → second → third.
  2. First pop. Removes "third" (last in).
  3. Second pop. Removes "second".
  4. LIFO pattern. Remaining stack is ["first"].

Browser & Runtime Support

Array.prototype.pop() is one of the oldest array methods, available since JavaScript 1.2 / ES3.

✓ Baseline · ES3

Array.prototype.pop()

Supported in every browser ever shipped with JavaScript arrays, including Internet Explorer, and all Node.js versions.

100% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.pop() Universal

Bottom line: Safe to use in any environment. No polyfill needed.

Frequently Asked Questions

pop() removes the last element from an array, shortens length by one, and returns that removed element.
Yes. pop() changes the array in place by removing the final element and updating length.
undefined. The array stays empty and length remains 0.
push() adds to the end; pop() removes from the end. Together they implement a LIFO stack.
pop() removes from the end. shift() removes from the start (and is usually slower on large arrays).
pop() has been available since JavaScript 1.2 / ES3. It works in every browser, including very old ones.

Next: push()

Learn how to append one or more elements to the end of an array.

push() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

14 people found this page helpful