Interview Preparation JavaScript ES6+ Subjective
May 10, 2013

What is Shift() method in Javascript?

Detailed Explanation

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.

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback