unshift

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

Applies to

Array

Syntax

arrayName.unshift(elt1,..., eltN)

Parameters

elt1...eltN

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.

myFish = ["angel", "clown"];
Console.Write("myFish before: " + myFish);
unshifted = myFish.unshift("drum", "lion");
Console.Write("myFish after: " + myFish);
Console.Write("New length: " + unshifted);

This example displays the following:

myFish before: ["angel", "clown"]
myFish after: ["drum", "lion", "angel", "clown"]
New length: 4

See also

Array: pop, Array: push, Array: shift