Home JavaScript Array Methods shift() JavaScript Array shift() Method Definition Array.prototype.shift() removes the first element, re-indexes the rest, shortens length by one, and returns the removed value. It mutates the array. Pair with push() for a simple FIFO queue.
array.shift()
["a", "b", "c"].shift() → "a"
array becomes → ["b", "c"]
empty array → undefined (no throw)
mutates the array ✓
shift = remove front
pop = remove end
unshift = add front Syntax Call array.shift. Start with this line.
Call What it does array.shift()Primary signature. array.shift(...)Call with the arguments your case needs.
Built into JavaScript. Call shift(...) on an array instance — no import required.
Library declarations Parameters Parameter Description Array Required. Source that will lose its first element
Return Value Return Value Description * Removed element, or undefined if empty
JavaScript Examples 1. Remove first 2. Empty array 3. FIFO queue Example 1 — Remove the First Element Shift "red" off a color list and inspect what remains.
const colors = ["red", "blue", "green", "yellow"];
const removed = colors.shift();
console.log(removed);
// "red"
console.log(colors);
// ["blue", "green", "yellow"] red
["blue", "green", "yellow"] How It Works Start with four colors. "red" sits at index 0.Call shift. It removes index 0 and returns "red".Everything slides left. "blue" becomes the new first item.Length drops. The array is now length 3.Example 2 — Empty Array Returns undefined shift() is safe on empty arrays — no error, just no value.
const empty = [];
const result = empty.shift();
console.log(result);
// undefined
console.log(empty.length);
// 0 How It Works Nothing to remove. Length is already 0.Return value. shift() yields undefined — same idea as pop() on empty.Array unchanged. It stays []; length remains 0.Guard tip. Check arr.length > 0 when empty means “do nothing.”Example 3 — FIFO Queue with push() and shift() Add at the back, remove from the front — first in, first out.
const queue = ["alice", "bob"];
queue.push("carol");
const served = queue.shift();
console.log(served);
// "alice"
console.log(queue);
// ["bob", "carol"] How It Works Start the line. Alice and Bob are already waiting.Enqueue. push("carol") adds Carol at the end.Dequeue. shift() serves Alice — she joined first.Order preserved. Bob and Carol remain in arrival order.Compatibility
Browser & Runtime Support Array.prototype.shift() has been part of JavaScript since ES3 / JavaScript 1.2 , alongside push, pop, and unshift.
✓ Baseline · ES3
Array.prototype.shift() Supported in every major browser (including Internet Explorer) and all Node.js versions. No polyfill required.
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.shift() Excellent
Bottom line: Safe everywhere. Use it freely for queues and front removal; for hot paths on huge arrays, consider designing around pop() instead.
Frequently Asked Questions What does Array.shift() do? shift() removes the first element from an array, shifts remaining elements down one index, shortens length by one, and returns the removed element.
Does shift() mutate the original array? Yes. shift() changes the array in place by removing index 0 and re-indexing the rest.
What does shift() return on an empty array? undefined. The array stays empty and length remains 0. It does not throw.
How is shift() different from pop()? shift() removes from the start. pop() removes from the end. With push, shift makes a FIFO queue; with push, pop makes a stack (LIFO).
How is shift() different from unshift()? shift() removes the first element. unshift() adds one or more elements at the start. They are opposites at the front of the array.
Which browsers support shift()? shift() has been available since JavaScript 1.2 / ES3. It works in every browser, including very old environments.
Next: slice() Learn how to copy a portion of an array without changing the original.
slice() tutorial → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
11 people found this page helpful
Helpful Share Copy link Suggestion