Promise.all()
Added in ves6 · Updated March 13, 2026 · Async APIs
promise async es6 javascript
Promise.all() is a static method that takes an iterable of promises and returns a single Promise that resolves to an array of results. It is useful when you need to coordinate multiple asynchronous operations that all must complete before proceeding.
Syntax
Promise.all(iterable)
Parameters
| Parameter | Type | Description |
|---|---|---|
iterable | Iterable | An iterable object (such as an Array) containing Promise objects or other values |
Return Value
Returns a Promise that:
- Resolves with an array of results when all input promises resolve
- Rejects immediately when any input promise rejects (fails fast)
If the input contains non-promise values, they are passed through to the result array unchanged.
Examples
Basic Usage
const promise1 = Promise.resolve(3);
const promise2 = Promise.resolve(42);
const promise3 = new Promise((resolve, reject) => {
setTimeout(resolve, 100, 'foo');
});
Promise.all([promise1, promise2, promise3])
.then((results) => {
console.log(results); // [3, 42, 'foo']
});
Real-World: Fetching Multiple APIs
async function fetchUserData(userIds) {
const requests = userIds.map(id =>
fetch(`/api/users/${id}`).then(r => r.json())
);
// Wait for all users to load
const users = await Promise.all(requests);
return users;
}
fetchUserData([1, 2, 3]).then(users => {
console.log(`Loaded ${users.length} users`);
});
Handling Mixed Values
// Non-promise values are passed through
const mixed = Promise.all([1, 2, Promise.resolve(3)]);
mixed.then(console.log); // [1, 2, 3]
Error Handling
const promises = [
Promise.resolve('success'),
Promise.reject(new Error('failed'))
];
Promise.all(promises)
.then(results => console.log(results))
.catch(error => {
// This runs because one promise rejected
console.error('At least one failed:', error.message);
});
Key Behaviors
- Fails fast: If any promise rejects, the entire
Promise.allrejects immediately - Preserves order: Results maintain the same order as the input iterable, regardless of resolve order
- Empty iterable: Returns a resolved promise with an empty array
Common Pitfalls
A common mistake is not handling rejection properly:
// DANGEROUS: This will reject if ANY promise rejects
const results = await Promise.all(requests);
// SAFER: Use Promise.allSettled if you need all results regardless of failures
const results = await Promise.allSettled(requests);
See Also
Promise.any()— Resolves as soon as any promise fulfillsPromise.race()— Resolves when the first promise settlesPromise.any()— Resolves when any promise resolvesPromise— The Promise object overview