Array.unshift

Adds one or more elements to the beginning of an array and returns the new length of the array.
Method of Array

Syntax

arrayName.unshift(element1,..., elementN )

Parameters

element1,...,element_N The elements to add to the front of the array.

Example

The following code displays the myFish array before and after adding elements to it.

This example produces the following results:
myFish before: ["angel", "clown"]
myFish after: ["drum", "lion", "angel", "clown"]
New length: 4

See also

Array.pop, Array.push, Array.shift

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.