Write the importance of shift() method in javascript array?

JavascriptObject Oriented ProgrammingProgramming

 Shift() 

This method is used to remove the element from an array.Moreover it is different from pop() because shift() method removes the element at the starting of the array.

 Live Demo

Example

<html>
<body>
<p id="shift"></p>
<script>
var a = [1,2,3,4,5];
var b = ["apple","mango","banana","guava","strawberry"]
a.shift();
b.shift();
document.write(a);
document.getElementById("shift").innerHTML = b;
</script>
</body>
</html>

Output

mango,banana,guava,strawberry
2,3,4,5
raja
Published on 21-May-2019 13:42:53
Advertisements