Array.shift() Remove the first item
Last updated: 2026-09-09
Array.shift() Remove the first item
shift removes the first element and returns it; an empty array returns undefined. With unshift it forms a queue (FIFO). Note shift is O(n).
| Category | Arrays |
|---|---|
| ES version | ES1 (1997) |
📝 Syntax
const removed = array.shift();
Returns:The removed first element, or undefined on an empty array.
Mutates the original:Yes (in place)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
customer1
2
undefined
⚠️ Warning shift is O(n) — every remaining element shifts left. Prefer a deque for hot paths.
💡 Tip const [first, ...rest] = arr destructures the head without mutating.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| Array.shift() | ✓ v1 | ✓ v12 | ✓ v1.5 | ✓ v3 | ✓ v10.5 |
| Supported by all modern browsers | |||||
🏷️ Related Array Methods
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qshift vs pop performance?
Apop is O(1); shift is O(n). Frequent shifts on big arrays become a bottleneck.
Qshift vs slice(1)?
Ashift mutates and returns the removed item; slice(1) returns a new array without mutating.
QHow to drain a queue safely?
Awhile (queue.length) { const item = queue.shift(); ... } — the loop ends naturally.