function zeroArray(m,n){
let newArray = [];
let row = [];
for (let i = 0; i < m; i++){
for (let j = 0; j < n; j++) {
row.push(0);
}
newArray.push(row);
}
return newArray;
}
let matrix = zeroArray(2, 2);
console.log(matrix)
The first row (after first for loop) is [[0,0]] but next time its [[0,0,0,0], [0,0,0,0]]. And I have no idea why the first row changed. Could you explain? I know that I could reset "row" after newArray.push(row) but then the result would be [[0,0], [0,0]] but I want this result: [[0,0], [0,0,0,0]].