Remove the Last Element of an Array with JavaScript pop

Web Dev
Sponsored links

In this article, I will introduce 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']