Remove the Last Element of an Array with JavaScript pop

02/15/2022
Contents
In this article, you will learn how to remove the last element of an array with JavaScript pop.
The pop() method
The pop() method removes the last element of an array and returns the removed element.
If the array is empty, this method returns undifined.
array.pop()
Sample Code
Below is sample code that removes the last element of the array.
let fruits = ['apple','orange','banana','lemon','grape'];
console.log(fruits); // ['apple','orange','banana','lemon','grape']
console.log(fruits.pop()); // 'grape'
console.log(fruits); // ['apple','orange','banana','lemon']