JavaScript array pop() function is “used to remove the last element from an array and returns that element”. It changes the original array.
Syntax
array.pop()
Parameters
None.
Return Value
It returns the removed element.
Example 1
let apps = [
{ name: 'Amazon', value: 1 },
{ name: 'Amazon Prime', value: 21 },
{ name: 'Amazon Music', value: 10 },
{ name: 'Amazon Go', value: 100 },
{ name: 'Amazon Alexa', value: 13 }
];
removedItem = apps.pop();
console.log('The remaining items are: ', apps);
console.log('The removed item is: ', removedItem);
The last item of an array is removed, and we can get that element.
Example 2
We can also perform the same operation with the integers of an array.
let numArr = [1, 3, 4, 5, 9];
let removedItem = numArr.pop();
console.log('The remaining items are: ', numArr);
console.log('The removed item is: ', removedItem);
Output
Example 3
let strArr = ['stan', 'bruce', 'warren', 'michael'];
let removedItem = strArr.pop();
console.log('The remaining items are: ', strArr);
console.log('The removed item is: ', removedItem);
Output
Example 4
If you call the pop() method on an empty array, it returns undefined. The length of the array becomes zero.
const numbers = [];
const last = numbers.pop();
console.log(last);
console.log(numbers.length);
Output
undefined
0
Example 5
The call() method is a predefined JavaScript method. With call(), an object can use a method belonging to another object. You can use the call() or apply() to call the pop() method on an array-like object.
let obj = {
0: "k",
1: "b",
2: "l",
length: 3
};
let last = Array.prototype.pop.call(obj);
console.log(last);
console.log(obj);
Output
l
{ '0': 'k', '1': 'b', length: 2 }
That’s it.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.