The pop() method removes the last element from an array, returns that value, and shortens the array by one. This tutorial covers syntax, five examples, empty-array behavior, stack patterns with push(), and how pop() differs from non-mutating methods like slice().
01
Syntax
arr.pop()
02
Last out
End removal
03
Returns
Removed item
04
Empty
undefined
05
Stack
LIFO + push
06
ES3
Universal
Fundamentals
Introduction
Arrays often grow and shrink. When you need to take something off the end—the most recently added item, the last breadcrumb, or the top of a stack—pop() is the built-in way to do it in one step.
Unlike map() or slice(), pop()mutates the original array. Always remember that the source array will be shorter after the call.
Concept
Understanding the pop() Method
array.pop() removes the element at index length - 1, decrements length, and returns the removed value. If the array is empty, it returns undefined and leaves the array unchanged.
Pair it with push() for a Last-In-First-Out (LIFO) stack: items go on top with push, come off top with pop.
💡
Beginner Tip
To read the last element without removing it, use arr[arr.length - 1] or arr.at(-1). Use pop() only when you want to remove it.
Foundation
📝 Syntax
General form of Array.prototype.pop:
JavaScript
array.pop()
Parameters
None.
Return value
The removed last element.
undefined if the array is empty.
Side effects
Mutates the array: length decreases by 1.
Former last index becomes a hole that is discarded (array compacts).
Common patterns
const last = arr.pop() — remove and capture.
while (stack.length) stack.pop() — drain stack.
if (arr.length) arr.pop() — guard empty arrays.
stack.push(x); stack.pop() — LIFO pair.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Remove last element
arr.pop()
Return value
Removed element or undefined
Read last without removing
arr.at(-1)
Remove first element
arr.shift()
Mutates array?
Yes
Compare
📋 pop() vs push() vs shift() vs slice()
Choose based on end vs start removal and whether you need to mutate.
pop
remove last
Mutates
push
add last
Stack pair
shift
remove first
Queue end
slice
copy portion
No mutation
Hands-On
Examples Gallery
Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.
📚 Getting Started
Remove the last item and inspect results.
Example 1 — Remove the Last Element
Pop "yellow" off a color list and see the shorter array.
slice copy: [10, 20]
original after slice: [10, 20, 30]
popped: 30
original after pop: [10, 20]
How It Works
slice(0, -1) returns everything except the last item without touching the source. pop() removes the last item for real.
Applications
🚀 Common Use Cases
Stack operations — undo/redo, call stacks, DFS.
Trim lists — remove the most recently added item.
History navigation — pop previous state after push.
Processing queues from the end — when order allows LIFO.
Drain arrays — while (arr.length) arr.pop().
Pair with push — dynamic stack without a class.
🧠 How pop() Runs
1
Check length
If zero, return undefined immediately.
Guard
2
Read last index
Capture value at length - 1.
Read
3
Decrease length
Array shrinks by one; last slot removed.
Mutate
4
📤
Return removed value
Caller gets the element that was at the end.
Important
📝 Notes
Mutates the array—length decreases by 1.
Empty array → returns undefined (no throw).
Return value is the removed element—store it if needed.
O(1) for end removal; shift() at start is slower on large arrays.
For immutable updates, use spread/slice: arr.slice(0, -1).
ES3—supported everywhere JavaScript runs.
Compatibility
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 3+, and all Node.js versions.
100%Universal support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.pop()Universal
Bottom line: Safe to use in any environment. No polyfill ever needed.
Wrap Up
Conclusion
pop() removes the last element, returns it, and shortens the array. Use it for stacks and LIFO logic with push(), or guard with length when empty state matters.
Next, learn push() to add elements to the end of an array.
Capture the return value when you need the removed item
Check length when empty state is meaningful
Pair with push for stack behavior
Use slice or spread when immutability is required
Prefer pop over splice(-1) for clarity
❌ Don’t
Assume pop() throws on empty arrays
Use pop when you only need to read the last item
Forget mutation affects all references to the array
Confuse pop with shift (start vs end)
Pop inside tight loops on huge arrays without reason
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.pop()
Remove the last element and get it back in one call.
5
Core concepts
📝01
Syntax
arr.pop()
API
📤02
Returns
Removed item.
Output
⚠03
Mutates
Length - 1.
Side effect
🗃04
Stack
LIFO + push.
Pattern
∅05
Empty
undefined.
Edge case
❓ Frequently Asked Questions
pop() removes the last element from an array, shortens the array 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 elements to the end; pop() removes the last element. Together they implement a LIFO stack.
pop() removes from the end (last in, first out). shift() removes from the start (first in, first out).
pop() has been available since JavaScript 1.2 / ES3. It works in every browser including very old environments.
Did you know?
pop() and push() are faster at the end of an array than shift() and unshift() at the start, because removing index 0 forces every other element to move down.