Hello World !
First, I apologize for my english that can be bad. I have a code that I can’t understand. Here it is :
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(3, 2);
console.log(matrix);
It returns me this in the console :
[ [ 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0 ] ]
I don’t understand why it returns this instead of that :
[ [ 0, 0 ],
[ 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0 ] ]
The row array contain [0, 0] at the first outside loop cycle, but the first value of newArray contain [0, 0, 0, 0, 0, 0].
Thank for helping !
Sam