Favorites

JavaScript Array.prototype.shift() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.shift()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The shift() method removes the first element of an array and returns it, moving the other elements down.

Description

The shift() method removes the first element and returns it, shifting all other elements down by one index. Together with push(), it lets you use an array as a queue (first in, first out).

On very large arrays, shift() is slow because every element moves; for big queues, keep an index pointer instead.

An array used as a queue with push() and shift() processes items in the order they arrived, which suits task lists and breadth-first searches. Inside a while (queue.length) loop, shift() gives you the next item to process. To read the first element without removing it, use arr[0] or arr.at(0).

Syntax

array.shift()

Return Value

The removed element, or undefined if the array was empty.

Example

const queue = ['first', 'second', 'third'];
console.log(queue.shift());
console.log(queue);

Browser Support

The following information will show you the current browser support for the Array.prototype.shift() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee