Whenever you use pop() on an array, the method does the following:
- It removes its calling array’s last item.
- It returns the removed item.
Syntax of the pop()
Method
pop()
accepts no argument. Here is the syntax:
Example 1: Remove an Array’s Last Item
Try it on StackBlitz
You can see that pop()
removed and returned numbersArray
’s last item (4
).
Also, note that pop()
changed the original array’s length.
Example 2: Remove an Array’s Last Item
Try it on StackBlitz
The snippet above used pop()
to pop out fruitsArray
’s last item.