Starting from a 2 dimensional array M
let M = [[1,1],[1,1]];
I would expect the code
let N = Object.assign([], M);
to create a copy of M. In other words to my understanding of Object.assign I should now have two identifiers M,N pointing to different locations in memory, with both locations containing the same 2-dimensional array.
However when I mutate an entry of N, the same entry in M changes as well:
N[0][0] = 0;
console.log(N);
console.log(M);
gives
> Array [Array [0, 1], Array [1, 1]]
> Array [Array [0, 1], Array [1, 1]]
Why is that? A analog example works as expected if M is a list instead of a list of lists.