Last Updated : 11 Sep, 2024
The pop() method removes (pops) the last element of an array. The pop() method changes the original array.
It reduces the array's length by one and returns the removed element.
Syntax:arr.pop();
Example 1: In this example, This function func() initializes an array arr, then removes and logs its last element using the pop() method.
JavaScript
function func() {
let arr = ['GFG', 'gfg', 'g4g', 'GeeksforGeeks'];
// Popping the last element from the array
console.log(arr.pop());
}
func();
Example 2: In this example this func() function initializes an empty array arr and attempts to remove the last element using the pop() method.
JavaScript
function func() {
let arr = [];
// popping the last element
let popped = arr.pop();
console.log(popped);
}
func();
Supported Browsers:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4