🎉
💨
Pop goes the last car! Let's learn to remove items from the end.
The pop() Method
The pop() method removes the last item from an array and returns it.
It's like uncoupling the last train car and letting it roll away!
💡
💨
How pop() Works
1const fruits = ["🍎", "🍌", "🍊"];23// Remove the last item4const removed = fruits.pop();56console.log(removed); // "🍊"7console.log(fruits); // ["🍎", "🍌"]
Watch it Happen!
[
1
[0]2
[1]3
[2]4
[3]5
[4]]
length: 5
1
Start with an array
We have [1, 2, 3, 4, 5]
🎮
Try It Yourself!
Click pop() to remove items from the end. The removed value will appear below!
[
1
[0]2
[1]3
[2]4
[3]5
[4]]
length: 5