JavaScript provides pop() method to remove the last element from array. pop() also returns the removed element.
Note: pop() method modifies the original array.
let groceryList = ["Milk", "Bread", "Garlic"]; console.log(groceryList); let lastElement = groceryList.pop(); console.log(groceryList); console.log(lastElement);
Output
["Milk", "Bread", "Garlic"] ["Milk", "Bread"] "Garlic"