JavaScript array pop() method

The pop() method removes the last element from an array and returns the removed element. In the example above, the last element in the fruits array is “Mango”, which is removed by the pop() method and stored in the lastElement variable.

After the pop() method is called, the fruits array is shortened by one element and no longer contains “Mango”. You can use the console.log() method to view the updated array and the removed element.

var fruits = ["Banana", "Orange", "Apple", "Mango"];

// Removes the last element ("Mango") from the fruits array
var lastElement = fruits.pop();

console.log(fruits);  // Output: ["Banana", "Orange", "Apple"]
console.log(lastElement);  // Output: "Mango"

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: