Multidimensional arrays

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 :slight_smile:

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]

1 Like

thank you so much. now i clearly understand.

1 Like