Easy

Remove the Last Element Using pop()

Description

Your task is to write a function that removes the last element from an array using the pop() method and returns the removed element.

The pop() method is a fundamental array operation in JavaScript that allows you to remove and retrieve the last item from an array.

If the array is empty, the function should return null.

Understanding how to manipulate arrays using methods like pop() is crucial for working with dynamic data structures in JavaScript.

Example usage:

console.log(removeLastElement(["apple", "banana", "cherry"])); // Output: "cherry"
console.log(removeLastElement([])); // Output: null

window code 2Test Cases

Input:

[
  5,
  10,
  15
]

Expected Output:

15