What did you expect to happen instead? What were you trying to achieve with changes made to the example?
I’m asking because otherwise it’s hard to say why it might be surprising. Code does what’s written in it. If change was made for a specific purpose and result is not as expected - that’s something that can be explained - either what’s wrong or why something else happens.
Strange thing, I ran the code which I explained above, both ran fine. I think now my confusion is around the nested loop
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
From my understanding is
when i = 0 which is item [1, 2] is array, it goes down to nested loop and j = 0; and j is less than length of [1, 2], it will console logging first item from arr and as j is asking what is first item of first item, it is printing that out?