Expert Developer JavaScript Question: Download Questions PDF
What is Shift() method in Javascript?
![Expert JavaScript Developer Interview Answer Expert JavaScript Developer Interview Question](https://globalguideline.com/public/images/interview/22.png)
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.
► 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 Interview Questions And Answers
PDF
Previous Question | Next Question |
What is the function of Deferred scripts? | Why would you include 'use strict' at the beginning of a JavaScript source file? |