The easiest way to empty an Array in Javascript

To empty an array in Javascript, simply set the length of the array to 0.

See the example below.

let arr = [1,2,3,4];

console.log(arr); // 1,2,3,4

arr.length = 0;

console.log(arr); // []

Screenshot of code showing how to empty array in Javascript

Want to learn how to code and make money online? Check out CodingPhase (referral link)