You'll want to make use of promises and arrays quite heavily to achieve what you want. Since promises are non-blocking (and therefore won't block the for loop) you'll need to collect your promises and wait for them all to finish executing before you can access all of the results. You can use the
Promise.allSettled
method to do that.
To append values to an array you just need to create an array and use the
push
method:
let values = [];
value.push(..);
I've put together
a JSFiddle which shows how to use Promise.allSettled[
^] which simply uses a random delay in a method call to simulate the HTTP request. All you'd need to do is retrofit what I've provided into your own code.
Worth noting that I'm not sure exactly what happens when an exception occurs (ie when a
catch
block would be required), might be worth trying it out and maybe doing some further research.