Back to Posts

Adding and removing items to arrays

By: Daniel Jimenez | Published on: May 11 2021




Use these 4 Javascript methods to either Add, Remove items to an array. There are many other methods that can be used, but for now I will go over Push, Pop, Shift, and Unshift.


In the array avengers, Hawkeye was added to the end of the array.
Added Hawkeye to the end of the array

PUSH()

This method will add the items to the end of the array.


Removed Captain America from the array
Removed Captain America from the array

POP()

This method will remove the last item in an array


Removed Spiderman from the avengers array
Removed Spiderman from the avengers array

SHIFT()

This method removes the first item of the array, like POP() but Shift removes the first item.


Added Scarlet Witch to the beginning of the array
Added Scarlet Witch to the beginning of the array

UNSHIFT()

This method will add the items in the beginning of the array, like PUSH() but Unshift will add it to the beginning.


Share:





2022 © Copyright, Daniel Jimenez