Array methods

Array.prototype.unshift()

Try the free JavaScript compiler

Inserts supplied values at the beginning in argument order, shifts existing positions and returns the new length. Mutates the receiver.

Formal Syntax & Structure

javascript syntaxjavascript
array.unshift(...items)

Parameters & Attributes

NameTypeDescription
itemsanyValues to prepend.

Return Value

Number

New length.

Working Example

Example Snippetjavascript
const a=[4];console.log(a.unshift(1,2),a.join(","));
JavaScript Reference