Promise.all
Takes 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
Syntax
Promise.all(iterable)Parameters
| Parameter | Type | Description |
|---|---|---|
| iterable | Iterable<Promise<T>> | An iterable of promises |
Return Value
A Promise that resolves to an array of results, or rejects with the first rejection reason
Examples
const p1 = Promise.resolve(1);
const p2 = Promise.resolve(2);
const p3 = Promise.resolve(3);
Promise.all([p1, p2, p3]).then(console.log); // [1, 2, 3]async function fetchMultiple(urls: string[]) {
const responses = await Promise.all(
urls.map(url => fetch(url))
);
return Promise.all(responses.map(r => r.json()));
}Promise.all([Promise.resolve(1), Promise.reject('error')])
.catch(err => console.log(err)); // 'error'Understanding Promise.all
The Promise.all method in JavaScript takes 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. 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.all(iterable). It accepts 1 parameter: iterable. When called, it returns a promise that resolves to an array of results, or rejects with the first rejection reason. Understanding when and how to use all() helps you write more expressive, readable code.
Common use cases for Promise.all include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like promise-allsettled, promise-race, promise-any, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Promise.all 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.allSettledTakes an iterable of promises and returns a promise that resolves after all promises have settled (fulfilled or rejected)
Promise.raceTakes an iterable of promises and returns a promise that settles with the eventual state of the first promise that settles
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
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.