I’ve created a two dimensional array with const foo = Array(n).fill(Array(n).fill(0)); and when updating foo[1][1] = 2 it changed all cell in column 1.

Why JS, why?!!!.

Javascript multidimensional array updating specific element.

Comments

How to respond

Write your comment on your on page and link it to this page with the following link:
https://vmac.ch/posts/2023-12-10-javascript-multidimensional-array-updating-specific-element-1702189510/
Then insert the permalink to your post into the form below and submit it.

Alternatively you can reach me by email to: comment@vmac.ch