ScanSkill

shift

The shift() method is used to remove items from inside the array.

Syntax

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.

Example

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.