ES6

Promise.all find resolved and rejected

promise.all

promise.all

As we all know Promise.all() rejects as soon as one of the Promises in the array rejects. But with that, we do not come to know :

  1. Which promise lead to the whole promise.all rejection.
  2. In the promises array which all promises resolved and which all rejected.

So here we will be discussing the solution of the above 2 problem statements.

Finding the index of rejected promise

Here we will try to find the index of the promise which resulted in the rejection of the Promise.all.

To achieve this we are using the mapper function along with the catch block, where we map the index of the promise being rejected.

Finding the resolved and rejected promised with promise.all

There are scenarios when we need to find which all promises resolved and which all rejected from the array or promises given. So we can do this by mapping each promise and using then/catch block we can assign a status to each promise resolved/rejected.
Below is the live code where you can see we have filtered the resolved promises and rejected promises.

Let me know your thoughts