For loop inside For Loop Javascript

前端 未结 2 957

For some reason this statement is skipping some data.Am I missing a continue statement somewhere or something ? Here is the code

for (var i = 0, len = data.ORDER         


        
相关标签:
2条回答
  • 2021-02-14 22:47

    Use a different variable on the inner loop, like j instead of i.

    for (var i = 0, len=data.ORDER_STATUS[0].ORDERS.length; i < len; i++) {
        //...
    
       for (var j = 0; j < data.ORDER_STATUS[0].ORDERS[i].LEGS.length; j++){
           //...
           data.ORDER_STATUS[0].ORDERS[i].LEGS[j].SYMBOL + 
    
    0 讨论(0)
  • 2021-02-14 23:07

    you are using "i" in your outer an inner loops. you need to use a different variable in the inner loop: i have used "inner" below as and example.

    for (var i = 0, len=data.ORDER_STATUS[0].ORDERS.length; i < len; i++) {
        if (data.ORDER_STATUS[0].ORDERS[i].SEC_TYPE=="MLEG"){
          for (var inner = 0; inner  < data.ORDER_STATUS[0].ORDERS[i].LEGS.length; inner ++) {
              // do something
          }
        }
      }
    
    0 讨论(0)
提交回复
热议问题