JS-055

Beginner4 min~4 min read#array#pop#arrays
pop()
Remove from the end of an array
Goal
Learn to remove the last element of an array using pop().
Explanation
- pop() removes the last element of an array.
- After pop() is called, the array becomes shorter.
- The method changes the original array.
- It specifically removes the last element.
- pop() is often used when working with a stack of data.
Analogy
Imagine a stack of plates. pop() removes the top plate from the stack.
Code
const fruits = [
"Apple",
"Banana",
"Orange"
];
fruits.pop();
console.log(fruits);Result: ["Apple", "Banana"]
Common mistake
Beginners sometimes think pop() removes the first element. In fact, it only works with the last one.
Remember
- ✦ pop() removes the last element.
- ✦ pop() changes the array.
- ✦ It works with the end of an array.
Quick Quiz
What remains after calling pop() on ["Apple", "Banana", "Orange"]?