I have the code in native JavaScript (I simplified it):
var finalArray = [];
for (var i; i < 3; i++) {
var a = -1; // set the default value
var b = Math.random();
ymaps.route(someArray[i]).then(function (res) {
a = res.getCoordinates();
});
finalArray.push([a, b]);
}
console.log(finalArray);
There is some third-party framework called ymaps which has a method route which returns a promise object. Problem cases in that I need to wait until promise.then callback function is done, then continue the main code with function finalArray.push([a, b]);, or, rather, synchronize asyncronous processes.
Result of code I wrote above is
[
[-1, /*random*/],
[-1, /*random*/],
[-1, /*random*/]
]
But instead of -1 - the default var a value, some plural number (changed var a in promise.then callback function) must be there.