Expert Developer JavaScript Question: Download Expert JavaScript Developer PDF

What is Shift() method in Javascript?

Tweet Share WhatsApp

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.

Download Expert JavaScript Developer PDF Read All 150 Expert JavaScript Developer Questions
Previous QuestionNext Question
What is the function of Deferred scripts?Why would you include 'use strict' at the beginning of a JavaScript source file?