I really can’t understand multidimensional arrays and how to access every element, why using arr[i].length on the inner loop? , any help will be appreciated
var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
because you have array in array when you use arr[i].length it returns length of 2 levels of depth array . when i = 0 it returns length of [1, 2], when i = 1 it returns length of [3, 4]