Push, Pop, Shift & Unshift

Zain Zafar
Aug 6 · 2 min read

JavaScript offers a number of ways to add and remove items at the start or at the end of an array. Without further ado let’s explore these methods.

Push

The push() method adds one or more elements to the end of an array and returns array and returns the new length of the array.

Ref: https://mzl.la/2yJPgxq

Pop

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

Ref: https://mzl.la/2yNrHUp

Shift

The shift() method removes the first element from an array and returns that removed element. This method changes the length of the array.

Ref: https://mzl.la/2Tf2FHw

Unshift

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

Ref: https://mzl.la/2YPSEpf

Conclusion

This article seems really short, but one needs to understand what these methods have to offer and how they effect JavaScript arrays behind the scene. For example immediate return values when one of these methods is called.

Zain Zafar

Written by

Frontend Enthusiast, JavaScript Hacker with affinity to Design & Blogger

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade