Javascript array shift() is an inbuilt function that removes the first item from an array and returns that deleted item. The shift() method changes the length of the array on which we are calling the shift() method. Javascript Array Shift method is not  pure function as it directly modifies the  array.

Javascript Array Shift Example

Javascript shift() method removes the item at the zeroeth index and shifts the values at consecutive indexes down, then returns that removed value.

If we want to remove the last item of an array, use the  Javascript pop() method.

If the length property is 0,  undefined is returned.

The syntax for shift() method is the following.

array.shift()

An array element can be a  string, a number, an  array, a boolean, or any other  object types that are allowed in the Javascript array. Let us take a simple example.

#javascript #array.prototype.shift #javascript pop #javascript shift

Javascript Array Shift Example | Array.prototype.shift()
2.20 GEEK