Javascript unshift array method

unshift

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

Syntax

arrayName.unshift(element1, …, elementN)

Example

// assumes a println function exists
myFish = [“angel”, “clown”];
println(“myFish before: ” + myFish);
unshifted = myFish.unshift(“drum”, “lion”);
println(“myFish after: ” + myFish);
println(“New length: ” + unshifted);

Output

myFish before: [“angel”, “clown”]
myFish after: [“drum”, “lion”, “angel”, “clown”]
New length: 4
DOWNLOAD SOLUTION HERE