Q:
What is Shift() method in Javascript?
Answer
-The shift() method is similar as the pop() method but the difference is that Shift method works at the beginning of the array.
-The shift() method take the first element off of the given array and returns it. The array on which is called is then altered.
For example
var myarray = ["apple ", "banana ", "mango "];
console.log(myarray.shift());
console.log(myarray);
we get the following console output:
apple
["banana ", "mango "];
When we call shift() on an empty array, it will return an undefined value.
View answer
Workspace
Report Error
Discuss