The shift()
method is used to remove items from inside the array.
array.shift()
The shift()
method attaches to the right side of an array with the .
operator. The shift method removes item from the left side of the array.
const fruits = ['apple', 'mango', 'banana'];
fruits.shift();
console.log(fruits); // Prints: [ 'mango', 'banana' ]
fruits.shift();
console.log(fruits); // Prints: [ 'banana' ]
We can see that the shift()
method removes an item from the start of the array.