Promise.all()
Runs promises in parallel and resolves with all results (or rejects fast).
Promise.all([promise1, promise2, ...])This static page keeps the syntax and examples indexed for search, while the coding app handles interactive exploration and saved references.
What it does
Overview
Runs promises in parallel and resolves with all results (or rejects fast).
Promise.all() accepts an iterable of promises and returns a single Promise that resolves to an array of results. It is the primary tool for aggregating the results of multiple asynchronous operations that can run concurrently. Performance-wise, it reduces total execution time to the duration of the longest promise rather than the sum of all durations. However, it implements a 'fail-fast' mechanism: if any input promise rejects, the returned promise immediately rejects with that reason, discarding results from other pending promises. If an empty iterable is passed, it returns a synchronously resolved promise. Non-promise values in the iterable are automatically wrapped via Promise.resolve() and included in the final array. IE not supported.
Quick reference
Syntax
Promise.all([promise1, promise2, ...])
Inputs
Parameters
See it in practice
Examples
Parallel Independent Requests
const p1 = Promise.resolve(3);
const p2 = 42;
const p3 = new Promise((resolve) => setTimeout(resolve, 100, 'foo'));
Promise.all([p1, p2, p3]).then(values => {
console.log(values);
});[3, 42, "foo"]
Aggregates multiple values, including non-promise constants, into a single result array in the order they were provided.
Handling Fail-Fast Rejections
const p1 = Promise.resolve('Success');
const p2 = Promise.reject('Error: Failed');
const p3 = new Promise((resolve) => setTimeout(resolve, 500, 'Slow Success'));
Promise.all([p1, p2, p3])
.then(values => console.log(values))
.catch(error => console.error(error));"Error: Failed"
If any promise in the array rejects, the entire operation fails immediately regardless of other pending promises.
Mapping Data to Concurrent Promises
const ids = [1, 2, 3];
const fetchData = (id) => Promise.resolve(`Data for ${id}`);
const requests = ids.map(id => fetchData(id));
Promise.all(requests).then(results => {
console.log(results);
});["Data for 1", "Data for 2", "Data for 3"]
Common pattern for transforming an array of data into an array of concurrent asynchronous operations.
Debug faster
Common Errors
LogicError
Cause: Expecting partial results when a rejection occurs.
Fix: Use Promise.allSettled() if you need the results of all promises regardless of whether some fail.
Promise.all([p1, failingP2]).catch(err => 'Still need p1 result');TypeError
Cause: Passing a non-iterable value (like a plain object) as the argument.
Fix: Ensure the input is an Array or another iterable type.
Promise.all({ task1: p1, task2: p2 });Runtime support
Compatibility
Source: MDN Web Docs
Common questions
Frequently Asked Questions
Runs promises in parallel and resolves with all results (or rejects fast).
iterable: Promises (or values) to await in parallel.
LogicError: Use Promise.allSettled() if you need the results of all promises regardless of whether some fail. TypeError: Ensure the input is an Array or another iterable type.