AshKeys

Confessions and Confusions of a Freelance Fullstacker.

Ashok Mannolu Arunachalam, BlogArrayJS
Back

Few ways to add and remove items in an array

There more than one way to add an item to an array and remove an item from an array in JavaScript. Let's see how can we do that in this post.

push and pop methods

push and pop methods usage

push inserts the elements at the end whereas pop pops out the top one that is the last item in the array.

shift and unshift methods

shift and unshift methods usage

shift removes the first element of an array whereas unshift does exact the opposite.

It is called shift because once the method is called the items of an array shifts one position left if one pictures the array horizontally. \O/