search

Home  >  Q&A  >  body text

javascript - nested for loop


The length of the addLocationMsg output by the nested output of the two for loops is 1. The following console.log('aaaaaa') is indeed output twice. Does anyone know what causes this problem? reason

漂亮男人漂亮男人2789 days ago550

reply all(5)I'll reply

  • 漂亮男人

    漂亮男人2017-05-19 10:11:39

    The existing error is that undefined, location and zonesName are not initialized. The answer cannot be seen. It is recommended to use a browser to debug and see the values ​​of these two properties. Whether it has not been initialized,

    reply
    0
  • 巴扎黑

    巴扎黑2017-05-19 10:11:39

    You can output this.addLocationMsg before and after the loop to see what changes have occurred in its content. Just put a breakpoint and you will know

    reply
    0
  • 迷茫

    迷茫2017-05-19 10:11:39

    The problem has been solved. I thought that the locationList changes dynamically, so it should be placed in the outer loop. Moreover, there is a problem with the push, which causes an undefined to be pushed, so the following error appears

    reply
    0
  • 習慣沉默

    習慣沉默2017-05-19 10:11:39

    The last line, the looped object is changed during the loop

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-19 10:11:39

    Did you use the vue framework?

    reply
    0
  • Cancelreply