JavaScript(JS) array method - pop

https://‮figi.www‬tidea.com

The pop() method is a built-in JavaScript array method that removes the last element from an array and returns that element. It modifies the original array.

Here's an example of how to use the pop() method:

let numbers = [1, 2, 3, 4, 5];

let lastNumber = numbers.pop();

console.log(numbers); // [1, 2, 3, 4]
console.log(lastNumber); // 5

In this example, we have an array numbers containing the elements [1, 2, 3, 4, 5]. We use the pop() method to remove the last element (which is 5) from the numbers array, and store it in the variable lastNumber. The pop() method modifies the original numbers array by removing the last element (5). We then log the modified numbers array and the removed element 5 to the console.

Note that if the array is empty, the pop() method returns undefined.