.allSettled()
The .allSettled()
method returns a new Promise object that resolves to an array after all Promises in iterableObject
have been resolved or rejected. This is ideal when working with multiple Promises that are independent of one another’s completion. Each element in the resolved array will be the result of the Promises in iterableObject
.
Syntax
Promise.allSettled(iterableObject);
The iterableObject
is usually an array of Promise objects. If the array is empty, a Promise object that resolves into an empty array will be returned.
Example
With an empty array:
Promise.allSettled([]).then((values) => {console.log(values); // Output: []});
Codebyte Example
With an array of Promises:
All contributors
- garanews222 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- BrandonDusch580 total contributions
- garanews
- christian.dinh
- Anonymous contributor
- BrandonDusch
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.