Array.unshift

unshift — Adds a new value to the beginning of the array.

Description

Array.unshift(mixed value)

Parameters

Name Description Type Default Optional
value mixed No

Return values

integer. The new length of the array.

Examples

Example #1 – unshift example
var array = [4, 8, 16, 32]; console.log(array); // [4, 8, 16, 32] console.log(array.length); // 4 console.log(array.unshift(2)); // 5 console.log(array); // [2, 4, 8, 16, 32] console.log(array.length); // 5

See also

External references