The shift() method is used to remove the first element of an array from the zero index and shift to the consecutive index and this is also used to change the length of an array .
syntax :
array.shift();
Example :
var arr = ['Mukesh', 'Ayush', 'Ravi' ] ;
alert(" before shift() method " + arr);//output : Mukesh Ayush Ravi
var shifting = arr.shift();
alert("after using shift() method" + arr) ; //output : Ayush Ravi
If you want to see Removed element from an array, you can see with the help of shifted element.
Example :
alert(" Removed Element is " + arr); //output :Mukesh
Note
If the lenght of an array is zero, then it will return undefined
1 Comment(s)