In JavaScript, there are several methods to clear all elements from an array. Here are some common approaches:
Assigning a New Empty Array:
let arr = [1, 2, 3];
arr = [];
console.log(arr); // Output: []
Setting the length Property to 0:
let arr = [1, 2, 3];
arr.length = 0;
console.log(arr); // Output: []
Using the splice() Method:
let arr = [1, 2, 3];
arr.splice(0, arr.length);
console.log(arr); // Output: []