JavaScript (ES2026) reference · Array Methods
JavaScript Array shift() Method
Remove the first element of the array and return it, moving the other elements down. Returns undefined if empty.
JavaScript (ES2026) Since ES3
Syntax
array.shift()
Return value
The removed element, or undefined.
Examples
const queue = ["first", "second", "third"];
console.log(queue.shift(), queue);
Output
first [ 'second', 'third' ]
const jobs = ["a", "b"];
let job;
while ((job = jobs.shift()) !== undefined) console.log("processing", job);
Output
processing a processing b
Version history
| Version | Change |
|---|---|
| JavaScript ES3 | Added |
Related
array.unshift()· Add one or more elements to the start of the array and return the new length. Changes the array in place.array.pop()· Remove the last element from the array and return it. Changes the array; returns undefined if it is empty.array.slice()· Return a shallow copy of part of the array, from start up to (not including) end. The original is not changed.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial