Array methods: pop( ) and shift( )

Array methods: pop( ) and shift( )

·

1 min read

Array pop

With the Array method pop(), you can remove the last element from an array and it returns the removed element.

pop() changes the length of the array.If you call pop() in on an empty array, it will return undefined.

pop.gif

Array shift

shift() Is like pop() the difference is that shift() removes the first element in the array, on index 0.

shift.gif