0 day streak
javascript / beginner
Snippet

Array Push and Pop

The push() method adds one or more elements to the end of an array. The pop() method removes the last element from an array and returns it.

snippet.js
javascript
1
2
3
const stack = ["A", "B"];
stack.push("C"); // Adds to end
const removed = stack.pop(); // Removes from end
nodejs
Breakdown
1
stack.push("C")
Modifies the array to ["A", "B", "C"].
2
stack.pop()
Removes "C" and sets the removed variable to that value.