Which fix removes the bug?
const rows = Array(3).fill([]);
rows[0].push('a');
console.log(rows[1].length);
- Build each row:
Array.from({length:3}, () => []) - Build each row:
Array.from({length:3}, []) - Change
fill([])tofill(new Array()) - Push with
rows[0] = rows[0].concat('a')
fill puts the SAME array in every slot, so one push shows up in all rows.
Play Problem Solving ▸