Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.shift: removing the first element

shift removes index zero, moves remaining properties left, and returns the original first value.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.shift()

array.shift() reads index 0, moves each subsequent existing property one position left, deletes the last position, decreases length, and returns the value read. An empty array returns undefined and sets length to 0. Sparse holes are preserved by deleting the target property rather than materialized as undefined.

The method mutates its receiver, has linear cost for an ordinary array, and is generic for mutable array-like objects. It accepts no arguments. A null or undefined receiver throws TypeError. A getter, setter, Proxy, read-only property, or non-configurable index can throw; earlier moves need not be rolled back, so the mutation can be partial.

Examples

const values = ["a", "b", "c"];
console.log(values.shift(), values.join(","), values.length);
const sparse = [, "b", , "d"];
const first = sparse.shift();
console.log(first, sparse.length, Object.keys(sparse).join(","), sparse[0], sparse[2]);
const record = { 0: "x", 1: "y", length: 2 };
console.log(Array.prototype.shift.call(record), record[0], record.length, 1 in record);

Result

a b,c 2
undefined 3 0,2 b d
x y 1 false

Sources