async function processArray(array) {
let myOrderedArray = [];
for (const item of array) {
const value = await getValue(item);
myOrderedArray.push(value);
}
return myOrderedArray;
}
I want to go through the array, for each item perform an async operation, and then save the value I get back in a different array. This results array is ordered: I want the result value for item1
appear in the result at position 1, before item2
, and so on.
However, these are async calls. I cannot be sure that my async function calls return in the exact same order, since they're, well, not synchronous. How can I achieve something like this?