[removed] confused about how nested for loops work

前端 未结 5 898
傲寒
傲寒 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:21

    Do this:

    var newTimes = [];
    for (var i = 0; i < times.length; i++) {
            for(var x = 0; x < times[i].length; x++) {
                newTimes.push(times[i][x]);
                console.log(newTimes);  
    
    
            }
    
        }
    

    You are re-initializing newTimes each time through the loop.

提交回复
热议问题