0
I’ve done a lot of research on the subject and I still can’t find a solution.
When I run the code below, the loop proceeds before the API callback.
In the callback the variable this.userRoute.newRoute[i]. address is changed, so I need the loop to wait for callback, to proceed from the new value that was inserted into the array, which before callback does not exist and returns "Undefined".
My question is whether I can get the loop to wait for the callback to run to continue the execution.
for(let i = 0; i < this.userRoute.route.length; i++){
service.getDistanceMatrix(
{
origins: [this.userRoute.newRoute[i].address],
destinations: composeDestination,
travelMode: 'DRIVING',
}, this.calcRouteDistanceResult.bind(this)
);
}