Can anyone explain to me why I is a subarray here? Is it because I =0? but then we also declared J = 0 so im a bit confused?
const arr = [
[1, 2], [3, 4], [5, 6]
];
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array.
hi Enda, I think I responded to an earlier question you made about js also.
Did you understand that response okay? (didn’t get any response from you so just checking)