![]() |
VOOZH | about |
The pop() method in JavaScript is used to remove the last element from an array and return that element. It modifies the original array by reducing its length by one.
undefined.[ 'Apple', 'Banana', 'Mango', 'Orange' ] removed string from array: Orange
arr.pop();undefined []
The array is empty, there’s no element to remove, and the method returns undefined.
The pop() method is often used in stack data structures to remove the top element (LIFO-Last In, First Out).
30 20 [ 10 ]
Each call to pop() removes the last pushed element, just like removing items from a stack.