The shift method in JavaScript arrays eliminates the initial element from the specified array and provides that element as a return value. This operation modifies the length of the original array.
Syntax
The syntax for the shift method is illustrated as follows:
Example
array. shift()
Return
The first element of an array.
JavaScript Array shift method example
Let’s examine a scenario in which we will eliminate and retrieve the first element from an array.
Example
Example
<script>
var arr=["AngularJS","Node.js","JQuery"];
var result=arr.shift();
document.writeln(result);
</script>
Output:
Output
AngularJS