Array.prototype.shift()

Removes the first element from an array and returns it.

Since ES1 Spec ↗

Syntax

arr.shift()

Returns

any — The removed first element, or undefined if the array is empty.

Examples

const a = [1, 2, 3];
console.log(a.shift(), a);
Output
1 [ 2, 3 ]
console.log([].shift());
Output
undefined

Notes

Mutates the array in place and re-indexes remaining elements (O(n)). Returns undefined for an empty array. Use `pop` to remove from the end.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also