How do you empty an array? let's see how to clear it and empty all its elements
How do you empty an array?
The first one and easiest is to set its
const arr = [1, 2, 3, 4, 5]; arr.length = 0; console.log(arr); // expected output: 
The other way to empty an array is to mutate the original array reference, assigning an empty array to the original variable, for this reason it’s required to use
let instead of
let arr = [1, 2, 3, 4, 5]; arr = ; console.log(arr); // expected output: