JavaScript (ES2026) reference · Array Methods

JavaScript Array unshift() Method

Add one or more elements to the start of the array and return the new length. Changes the array in place.

JavaScript (ES2026) Since ES3

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

Syntax

array.unshift(element1, /* …, */ elementN)

Parameters

ParameterDescription
elements Elements to add at the front.

Return value

The new length.

Examples

Add to the frontTry it yourself
const list = ["b", "c"];
console.log(list.unshift("a"), list);

Output

3 [ 'a', 'b', 'c' ]
Most recent firstTry it yourself
const recent = ["page2", "page1"];
recent.unshift("page3");
console.log(recent.slice(0, 2)); // the two most recent

Output

[ 'page3', 'page2' ]

Version history

VersionChange
JavaScript ES3Added

In other languages

Was this page helpful?