Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Oct 20, 2022, 8:31 AM EDT
The push() is used to add an element/item to the end of an array.
The pop() is used to delete the last element/item of the array.
How to use the pop() method in JavaScript
Suppose we have an array of numbers and we want to remove the last element from it. The code from removing an element from the end of the array would go like this:
var intArr = [23, 45, 67]; intArr.pop(); // returns the removed item console.log(intArr);How to use the push() method in JavaScript
Similarly, if we want to add an element at the end of an array, the code for pushing or adding an element would go like this:
var intArr = [23, 45]; intArr.push(67); // returns the new array length console.log(intArr);Note:
The pop() method in JavaScript removes an item from the end of an array, whereas the push() method adds an item to the end of an array. The returning value of the pop() method is the item that is removed from the array.
Onkar SharmaRank #104 · 20.6K reputationPosted Nov 6, 2022, 8:52 AM EST
Hi,
To know more about "JavaScript array push and pop methods", visit:
[JavaScript array push and pop methods - YouTube] (https://www.youtube.com/watch?v=a4ZatfhxfnQ)
Thanks!
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Oct 20, 2022, 8:43 AM EDT
https://www.c-sharpcorner.com/article/working-with-array-in-javascript/
Brahma Prakash ShuklaRank #633 · 3.8K reputationPosted Nov 6, 2022, 2:08 AM EST
push() is used to add an element/item to the end of an array. The pop() function is used to delete the last element/item of the array. Let's try to add and remove elements from an array using push() and pop() methods to understand these methods better.