DEV Community

Cover image for Array.prototype.pop, push, shift, and unshift.
Ziad Smew
Ziad Smew

Posted on

Array.prototype.pop, push, shift, and unshift.

This tutorial is about array’s methods which will cover all the differences between them. Also, it will show when and how we should be using it

lets start with this array for this tutorial:
Image description

  • First one - Pop() is an array method to remove the last element of the array. The method Syntax is pop( ). Image descriptionOutput : [ 'Will', 'Bell', 'Anas' ]

  • Second one - Push() is an array method to add new element at the end of the array. The method Syntax is Push( ). Image descriptionOutput : [ 'Will', 'Bell', 'Anas', 'Adam', 'Zac' ]

  • Third one - Unshift() is an array method to add new element at the first of the array. The method Syntax is Unshift( ). Image descriptionOutput : [ 'Matt', 'Will', 'Bell', 'Anas', 'Adam' ]

  • Last one - Shift() is an array method to remove the first element of the array. The method Syntax is Shift( ). Image descriptionOutput : [ 'Bell', 'Anas', 'Adam' ]

ADDITIONAL RESOURCES:

Top comments (0)