Skip to content Skip to sidebar Skip to footer

For Loop Inside For Loop Javascript

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_STATUS[0].ORDERS.l

Solution 1:

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 + 

Solution 2:

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 (varinner = 0; inner  < data.ORDER_STATUS[0].ORDERS[i].LEGS.length; inner ++) {
          // do something
      }
    }
  }

Post a Comment for "For Loop Inside For Loop Javascript"