It's important understand how it works <Nesting for loops>

I tried this exercises in many ways, i did a search in google and saw many answer… and some help me a lot but i still with doubts!

  1. In this page i can try all the exercises if someone need see the results of the exercises for understand better i leave here:
  2. This is the exercise:
    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++) {

I need if someone can explain me why if the var i=0 my output is 123456 and when i change to var i = 1 my output is 3456… Thank you a lot

Hey @veroca88,
See, this your arr:


So, when i=0, the first loop in your code starts from first element of the array because arrays are zero-indexed and thus output includes[1,2].
However, when i=1, the loop begins with second element of the array.
And thus, output does not include [1,2].
Hope this answers your question.

:slight_smile: Thank you!! I got it

Always welcome.
Glad i could help.