1array.pop(); //returns popped element
2//example
3var fruits = ["Banana", "Orange", "Apple", "Mango"];
4fruits.pop(); // fruits= ["Banana", "Orange", "Apple"];
1const cars = ['Porsche', 'Ferrari', 'Mustang', 'Rolls Royce', 'Lamborghini'];
2
3console.log(cars.pop());
4// expected output: 'Lamborghini'
5
6console.log(cars);
7// expected output: Array ['Porsche', 'Ferrari', 'Mustang', 'Rolls Royce']
1const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];
2
3console.log(plants.pop());
4// expected output: "tomato"
5
6console.log(plants);
7// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]
1/*The pop() method removes an element from the end of an array, while shift()
2removes an element from the beginning.*/
3
4let greetings = ['whats up?', 'hello', 'see ya!'];
5
6greetings.pop();
7// now equals ['whats up?', 'hello']
8
9greetings.shift();
10// now equals ['hello']