Understanding nested for loops in javascript

前端 未结 7 1428
梦毁少年i
梦毁少年i 2021-01-30 09:39

I\'m learning JavaScript at the moment on freecodecamp and they have an example for nested for loops in one of their excercises:

 var arr = [[1,2], [3,4], [5,6]]         


        
相关标签:
7条回答
  • 2021-01-30 10:33

    Despite some caveats of using for-in loops on arrays, they can imo sometimes help to clear the mess in nested loops a bit:

    var arr = [[1,2], [3,4],[5,6]];
    
    for (i in arr){
          for (j in arr[i]){
            console.log(arr[i][j]);
          }
        }

    Also code visualization can clarify execution!

    0 讨论(0)
提交回复
热议问题