The shift method

The shift() method removes the first element of an array. It returns the value of the elements that was removed.

var Fruits = new Array("bananas" , "apples" , "pears", "mangoes");
document.write(Fruits);
Fruits.shift();
document.write("<br>"+Fruits);

You can assign the value of the method to a variable so you can use it later.

var Fruits = new Array("bananas" , "apples" , "pears", "mangoes");
var FavoriteFruit = Fruits.shift();
document.write(FavoriteFruit);

Leave a Reply