Confessions and Confusions of Ashok M A. Personal and Professional Blog.

Ashok Mannolu Arunachalam, BlogArrayJS

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/