Which of the following methods is used to remove the last element from an array in JavaScript?

Which of the following methods is used to remove the last element from an array in JavaScript?

a) pop()
b) shift()
c) splice()
d) remove()

Answer:

a) pop()

Explanation:

The pop() method is used to remove the last element from an array in JavaScript. It modifies the original array and returns the removed element.

Example:


let fruits = ["Apple", "Banana", "Cherry"];
let lastFruit = fruits.pop();
console.log(fruits); // Output: ["Apple", "Banana"]
    

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top