How to use push(), unshift(),pop() and shift() with array in javascript
Hello Readers, As the title gives you an idea of what is going to learn from this article.
We have a lot of functions, properties in any language and functionality-wise doing the same but there should be at least one difference.
As per the above statement, We use four functions in javascript and describe the functionality of those functions.
Here functionality is inserted and deleted from an array. Now, A question arises in your mind. Why we need 4 functions?
Let’s go in deeper to learn more about this,
As in array, We store data in memory associated with an index (Starting index is 0) to fetch the value.
Insert a new element we use push() and unshift() functions in javascript. Please look into an example in below screenshot,
Removing/Deleting existing element we use pop() and shift() functions in javascript. Please look into an example in below screenshot,
That’s all folks and hope with this article you cleared the differences between these functions in javascript.
Thanks for reading and will come up with basic and important concepts which we use but not clear in our day to day work.
— Happy Coding : )