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
inserts the elements at the end whereaspop
pops out the top one that is the last item in the array.
shift
and unshift
methods
shift
removes the first element of an array whereasunshift
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/