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
It's because the closure captures the variable i itself, not the current value. Try:
for (var i = 0; i < a.length; i++) (function(i)
{
calcRoute(fixedLocation, my_cities[i].address, function(response) {
// i want here to have the current "i" here
});
}) (i);
which will create a new i variable for each loop iteration.