-3

I have the array of promises. I'm using Promise.all to handle them all. But how can I take the array of values from it? Something like:

const myValueArr = Promise.all(myPromiseArr);

Cannot find respective example.

Thank you in advance

Kania
  • 2,342
  • 4
  • 28
  • 36
  • 2
    `const myValueArr = await Promise.all(myPromiseArr);` or `Promise.all(myPromiseArr).then(myValueArr => { ... });`. – Paul Apr 30 '19 at 15:15
  • 4
    First non-ad-supported hit on DuckDuckGo.com: [*`Promise.all` on MDN*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all). With examples. – T.J. Crowder Apr 30 '19 at 15:18
  • 1
    A [simple google search](https://www.google.com/search?q=javascript+how+to+get+result+of+promise.all) would have immediately given you the solution. – Jeremy Thille Apr 30 '19 at 15:19
  • @T.J.Crowder I love how you specified "non-ad-supported hit", lol. – briosheje Apr 30 '19 at 15:24
  • 1
    @briosheje - Well, the ad-supported one was for a film called "Promises, Promises" so... ;-) – T.J. Crowder Apr 30 '19 at 15:26
  • Unfortunately what I found was exactly as in both answers to my question. Not the thing I've needed. Big thanks to @Paulpro for answering my question. Unfortunately, I cannot mark the comment as the accepted answer – Kania May 05 '19 at 10:39

2 Answers2

1

The array of values will be the resolved value of the promise returned by calling Promise.all.

You get that value as you would the value of any promise resolution:

myValueArr.then( function (array_of_values) {
     do_something_with( array_of_values );
});

… or use async and await.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

You can use the then function to get the values as:

Promise.all(myPromiseArr).then(function(values) {
  console.log(values);
});
Vishnu
  • 897
  • 6
  • 13