JavaScriptAsyncIntermediate

Promise.all()

Runs promises in parallel and resolves with all results (or rejects fast).

Review the syntaxStudy the examplesOpen the coding app
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

iterableIterable<Promise> · Promises (or values) to await in parallel.

See it in practice

Examples

1

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);
});
Output:
[3, 42, "foo"]

Aggregates multiple values, including non-promise constants, into a single result array in the order they were provided.

2

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));
Output:
"Error: Failed"

If any promise in the array rejects, the entire operation fails immediately regardless of other pending promises.

3

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);
});
Output:
["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

1

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');
2

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

Node.js, BrowserAll modern browsersES6 (2015)

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.