Array shift() Method
The Array shift()
method removes and returns the first element of an array and shifts the indexes of the remaining elements one lower. The syntax for this method is
array.shift();
We consider an array named os
consisting of four elements
var os = ["Debian", "Fedora", "openSUSE", "Ubuntu"];
Applying the shift()
method on it will remove and return its first element Debian
, which is assigned to the variable first
var first = os.shift();
and the new modified array with one element less becomes
["Fedora", "openSUSE", "Ubuntu"];
The variable first
holds the returned value Debian
.