Using Array.push() and Array.pop() in Javascript


Add items to the end of an array with .push() and remove the last item with .pop().

Source Code

let fruits = ['apple', 'banana'];
fruits.push('cherry'); // ['apple', 'banana', 'cherry']
let lastFruit = fruits.pop(); // ['apple', 'banana']
console.log(lastFruit); // "cherry"
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments