const a = 3
const b = 4
const arr = new Array(a).fill([]);
for (let i = 0; i < a; i++) {
for (let j = 0; j < b; j++) {
arr[i][j] = i;
}
}
console.log(JSON.stringify(arr))
I would expect to return
[[0,0,0,0],[1,1,1,1],[2,2,2,2]]
but it returns
[[2,2,2,2],[2,2,2,2],[2,2,2,2]]
I think this is not because of the closure things but please let me know what is the problem of this code not working as expected.
* edited -> sorry, I forgot to paste initializing arr code *