Values & References16 / 18
Up next

fill shares one reference

// fill stores the SAME array in every slot
const rows = Array(3).fill([]);
rows[0].push(1);
console.log(rows);
// Array.from builds an independent object per slot
const safe = Array.from({ length: 3 }, () => []);
safe[0].push(1);
console.log(safe);
What you're solving

Array(n).fill puts the same object everywhere