Do you know what will be the output of this code?
JavaScript
const arr = [1, 2, 3, 4];
arr.length = 2;
console.log(arr);
Show answer and explanation
The answer is [1, 2].
length is writable. Making it smaller removes every item at or above the new length. Setting it to 0 empties the array.