Favorites

JavaScript Array.prototype.unshift() 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.unshift()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The unshift() method adds one or more elements to the start of an array and returns the new length.

Description

The unshift() method adds elements to the beginning of an array, moving the existing elements up, and returns the new length. It changes the array in place. To add to a copy instead, use [item, ...arr].

Like push(), it accepts several elements and adds them in the order given, so arr.unshift(1, 2) puts 1 first and 2 second. The return value is the new length, not the array.

Because every existing element has to move up by one position, unshift() gets slower as arrays get larger, so it isn't ideal for adding many items one at a time to a big array. Building the list in reverse with push() and reversing it once at the end, or creating a new array with spread syntax, is often faster.

Syntax

array.unshift(element1, element2, ...)

Parameters

  • element1, element2, ...The elements to add to the start of the array.

Return Value

The new length of the array.

Example

const list = ['b', 'c'];
console.log(list.unshift('a'));
console.log(list);

Browser Support

The following information will show you the current browser support for the Array.prototype.unshift() 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