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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

array.shift()

Return value

The removed element, or undefined.

Examples

Remove the first elementTry it yourself
const queue = ["first", "second", "third"];
console.log(queue.shift(), queue);

Output

first [ 'second', 'third' ]
Process a queueTry it yourself
const jobs = ["a", "b"];
let job;
while ((job = jobs.shift()) !== undefined) console.log("processing", job);

Output

processing a
processing b

Version history

VersionChange
JavaScript ES3Added

In other languages

Was this page helpful?