Javascript - how to work with the iterator in a for loop with callbacks

后端 未结 3 1198
无人共我
无人共我 2020-12-31 14:24

I am trying in the for loop to access the value of the i with which the callback function uses.

How can I do this?

for (var i = 0; i < a.length; i         


        
3条回答
  •  迷失自我
    2020-12-31 15:01

    for (var i = 0; i < a.length; i++) {
    
      function createCallback(i) {
        return function(response) {
          // i want here to have the current "i" here
        }
      }
    
      calcRoute(fixedLocation, my_cities[i].address, createCallback(i));
    }
    

提交回复
热议问题