unshift() method is used to add elements to the beginning of an array. The elements are sent as parameters to the method. The value returned by the method is the numeric value of the new length of the array.
var Fruits = new Array ("pears", "mangoes"); Fruits.unshift("bananas" , "apples"); document.write (Fruits); var NumberFruits = Fruits.unshift(); document.write("<br>Now there are "+NumberFruits+" fruits in the array");
The output will be “bananas,apples,pears,mangoes Now there are 4 fruits in the array”.