Promise.allSettled
Takes an iterable of promises and returns a promise that resolves after all promises have settled (fulfilled or rejected)
Syntax
Promise.allSettled(iterable)Parameters
| Parameter | Type | Description |
|---|---|---|
| iterable | Iterable<Promise<T>> | An iterable of promises |
Return Value
A Promise that resolves to an array of result objects with status and value/reason
Examples
const promises = [
Promise.resolve('ok'),
Promise.reject('fail'),
Promise.resolve('done'),
];
const results = await Promise.allSettled(promises);
console.log(results);
// [{status:'fulfilled',value:'ok'}, {status:'rejected',reason:'fail'}, ...]async function tryAll(tasks: Promise<unknown>[]) {
const results = await Promise.allSettled(tasks);
const successes = results.filter(r => r.status === 'fulfilled');
const failures = results.filter(r => r.status === 'rejected');
console.log(`${successes.length} succeeded, ${failures.length} failed`);
}const results = await Promise.allSettled([fetch('/api/a'), fetch('/api/b')]);
for (const r of results) {
if (r.status === 'fulfilled') console.log(r.value);
}Understanding Promise.allSettled
The Promise.allSettled method in JavaScript takes an iterable of promises and returns a promise that resolves after all promises have settled (fulfilled or rejected). It belongs to the Promise object and is one of the most widely used methods for working with promise values in modern JavaScript and TypeScript applications.
The method signature is Promise.allSettled(iterable). It accepts 1 parameter: iterable. When called, it returns a promise that resolves to an array of result objects with status and value/reason. Understanding when and how to use allSettled() helps you write more expressive, readable code.
Common use cases for Promise.allSettled include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like promise-all, promise-any, promise-race, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Promise.allSettled is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Promise.allTakes an iterable of promises and returns a single promise that resolves when all of the input promises have resolved, or rejects when any input promise rejects
Promise.anyTakes an iterable of promises and returns a promise that resolves as soon as any of the promises fulfills, with the value of the first fulfilled promise
Promise.raceTakes an iterable of promises and returns a promise that settles with the eventual state of the first promise that settles
More Promise Methods
Other methods in the Promise object
Related Tools
More Promise Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.