Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
The problem is that the fill function is filling the array with references to the same empty array[1], and therefore modifying that array will affect every entry because all of them are actually th...
Answer
#1: Initial revision
The problem is that the `fill` function is filling the array with *references* to the *same* empty array[^1], and therefore modifying that array will affect every entry because all of them are actually the same entry. To get around this, you need to explicitly create a new array for each index, for instance by using a for loop ```javascript const arrays = []; for (let i = 0; i < 3; i++) { arrays.push([]); } arrays[0].push('foo'); console.log(arrays); // [ [ 'foo' ], [], [] ] ``` [^1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/fill#description