考虑以下代码
let matrix1 = new Array(2).fill(new Array(2).fill(0));
let matrix2 = [
[0, 0],
[0, 0]
];
console.log(JSON.stringify(matrix1)); //[[0,0],[0,0]]
console.log(JSON.stringify(matrix2)); //[[0,0],[0,0]]
matrix1[0][0] = 5;
matrix2[0][0] = 5;
console.log(JSON.stringify(matrix1)); // [[5,0],[5,0]]
console.log(JSON.stringify(matrix2)); // [[5,0],[0,0]]
当我使用新的Array语法创建矩阵时,这些值会以两个元素而不是第一个元素进行更新。这是预期的行为还是我做错了什么