xxxxxxxxxx
/*The pop() method removes an element from the end of an array, while shift()
removes an element from the beginning.*/
let greetings = ['whats up?', 'hello', 'see ya!'];
greetings.pop();
// now equals ['whats up?', 'hello']
greetings.shift();
// now equals ['hello']
xxxxxxxxxx
let arr = [1, 2, 3, 4, 5];
let poppedElement = arr.pop();
console.log(poppedElement); // Output: 5
console.log(arr); // Output: [1, 2, 3, 4]
xxxxxxxxxx
//The pop() method removes and return the last element from an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const lastFruit = fruits.pop();
console.log(lastFruit) //>> "Mango"
console.log(fruits) //>> ["Banana", "Orange", "Apple"]
xxxxxxxxxx
Array.prototype.pop()
//The pop() method removes the last element from an array
//and returns that element.
//This method changes the length of the array.