Skip to main content

shift() in JavaScript – How to Remove First Array Element

Whenever you use shift() on an array, the method does the following:

  1. It removes its calling array's first item.
  2. It returns the removed item.

A calling array is an array on which you used shift(). So, in bestColorsList.shift(), bestColorsList is the calling array.

Syntax of the shift() Method


As shown in the snippet above, shift() does not accept any argument.

shift() Example 1

const numbersArray = [1, 2, 3, 4];


// The invocation above will return:

// Check the numbersArray's current content:

// The invocation above will return:
[2, 3, 4]

Try it on StackBlitz

You can see that shift() removed and returned numbersArray's first item (1).

Also, note that shift() changed the original array's length.

Example 2

const fruitsArray = ["Mango", "Apple", "Orange"];
const removedFruit = fruitsArray.shift();

console.log(removedFruit); // returns "Mango"
console.log(fruitsArray); // returns ["Apple", "Orange"]

Try it on StackBlitz

The snippet above used shift() to shift away fruitsArray's first item.

  • To remove an array's last item, use pop().
  • To remove an item at a specific index position, use the splice() method.


This article discussed what JavaScript's shift() method does. We also used examples to see how it works.

If you like this article, please Tweet it.

Thanks for reading!