I tried a lot ,but I still can not understand why what I have done here is not working as an approach of this challenge .

function zeroArray(m, n) {
// Creates a 2-D array with m rows and n columns of zeroes
let newArray = [];
let row = [];

for (let i = 0; i < m; i++) {
// Adds the m-th row into newArray
newArray.push(row);//here everytime I push a new arr (row) to newArray array
for (let j = 0; j < n; j++) {
// Pushes n zeroes into the current row to create the columns
newArray[i].push(0); //here newArray[i]=newArray[0], and in the second time it is gonna be newArray[i]=newArray[1];

}
// Pushes the current row, which now has n zeroes in it, to the array
newArray.push(newArray[i]);//here I push the last newArray[i] that I have just pushed to it two 0's
// the resutl [Array(6), Array(6), Array(6), Array(6), Array(6), Array(6)]

}
return newArray;// here the resut is different I dont know why
}

let matrix = zeroArray(3, 2);
console.log(matrix);

By the way, I can solve the problem using another method but I wanted to follow what they said to me to do in the comments.
I 'll apperciate any help ,thanks in advance.

function zeroArray(m, n) {
// Creates a 2-D array with m rows and n columns of zeroes
let newArray = [];
let row = [];
for (let i = 0; i < m; i++) {
// Adds the m-th row into newArray
for (let j = 0; j < n; j++) {
// Pushes n zeroes into the current row to create the columns
row.push(0);
}
// Pushes the current row, which now has n zeroes in it, to the array
newArray.push(row);
}
return newArray;
}
let matrix = zeroArray(3, 2);
console.log(matrix);

and the instructions (i bolded the most important part):

The following function is supposed to create a two-dimensional array with m rows and n columns of zeroes. Unfortunately, itâ€™s not producing the expected output because the row variable isnâ€™t being reinitialized (set back to an empty array) in the outer loop. Fix the code so it returns a correct 3x2 array of zeroes, which looks like [[0, 0], [0, 0], [0, 0]].

so, the inner loop is forâ€¦j and the outer loop is forâ€¦i
at the end of the outer loop, before the outer loop is closed, the row variable needs to be set back to zero

also, just a tip for posting code in the forums so people can read it:

When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The â€śpreformatted textâ€ť tool in the editor (</>) will also add backticks around text.

thanks megantaylor for this help
â€¦
for (let j = 0; j < n; j++) {
// Pushes n zeroes into the current row to create the columns
row.push(0);
}
/* here row is adding 0â€™s to the same array, I thought if I replace it by newArray[i] that will solve the issue /*
â€¦
I am still confused but ,I have passed the challenge using loop by another way .

The row needs to be reinitialized/declared in a different part of the code. Thereâ€™s actually no â€śwritingâ€ť involved. Just the movement of a piece of the code.

thank you tanhuy this helps , unfotunately the comments misleaded me , I considered them as instructions ,
Now I figured out that I should put let row=[] in the first loop to reinitialize the row variable.
thank you all campers.

Hi, and for all of you who are searching for a final solution, this is the right on.
Keyword is: move the empty array declaration inside the outer for loop

function zeroArray(m, n) {
// Creates a 2-D array with m rows and n columns of zeroes
let newArray = [];
for (let i = 0; i < m; i++) {
// Adds the m-th row into newArray
let row = [];
for (let j = 0; j < n; j++) {
// Pushes n zeroes into the current row to create the columns
row.push(0);
}
// Pushes the current row, which now has n zeroes in it, to the array
newArray.push(row);
}
return newArray;
}

let matrix = zeroArray(3, 2);
console.log(matrix);