[removed] confused about how nested for loops work

前端 未结 5 874
傲寒
傲寒 2020-12-17 02:49

Why do nested for loops work in the way that they do in the following example:

var times = [
            [\"04/11/10\", \"86kg\"], 
                     


        
5条回答
  •  無奈伤痛
    2020-12-17 03:27

    The problem is in the second round of the inner loop, where it pushes the second element into newTimes. Anyway I don't understand the reason of inner loop. You can write much simpler:

    var times = [
                ["04/11/10", "86kg"], 
                ["05/12/11", "90kg"],
                ["06/12/11", "89kg"]
    ];
    
    for (var i = 0; i < times.length; i++) {
        console.log(time[i][0]);  
        console.log(time[i][1]);   
    }
    

提交回复
热议问题