JavaScript: array.shift() vs array.unshift()

shift() removes the first array item, and unshift() prepends items to the array. But how to remember which is which?

Here's a mnemonic:

The methods with shorter names remove items.

So, pop() and push():

  • pop() has a shorter name than push()
  • pop() removes the last array item
  • push() appends items to the array.

Similarly, shift() vs unshift():

  • shift() has a shorter name than unshift()
  • shift() removes the first array item
  • unshift() prepends items to the array.