Promise.all() in JavaScript with Examples

Learn how Promise.all() works in JavaScript with parallel promise examples, rejection behavior, and real output.

Published

Updated

Read time 2 min read

Reviewed byDeepak Prasad

Promise.all() in JavaScript with Examples

Promise.all() is the JavaScript method you use when multiple promises can run in parallel and the next step should wait for all of them to finish. It is the standard pattern for grouped async work such as loading several resources at once.

The method resolves with an array of results in the same order as the input promises. If any promise rejects, the whole call rejects immediately. If you are comparing single-promise flows too, wait for async function to finish is the related article.

Tested on: Node.js v20.18.2. A short note after each runnable snippet describes what you should see in the console.


Method 1: Wait for parallel promises

Promise.all() waits for every promise in the list to resolve.

javascript
Promise.all([Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)])
  .then((values) => console.log("promise-all:", values.join(",")));
Output

You should see one line logging promise-all: 1,2,3.

Use this when the next step depends on all values being ready together.


Method 2: Handle rejections from Promise.all()

If one promise rejects, the combined promise rejects immediately.

javascript
Promise.all([Promise.resolve(1), Promise.reject(new Error("boom"))])
  .catch((error) => console.log("promise-all-error:", error.message));
Output

You should see one line logging promise-all-error: boom.

This behavior matters when you need all results or no result at all.


Method 3: Use Promise.all() with async/await

await keeps the grouped promise flow readable.

javascript
async function run() {
  const values = await Promise.all([Promise.resolve("A"), Promise.resolve("B")]);
  console.log("promise-all-await:", values.join(","));
}

run();
Output

You should see one line logging promise-all-await: A,B.

This is the cleaner form when you are already using async functions.


Summary

Promise.all() is the JavaScript tool for waiting on multiple promises at once. Use it when the operations can run in parallel and you only want to continue after every promise succeeds.


Official documentation

Olorunfemi Akinlua

Boasting over five years of experience in JavaScript, specializing in technical content writing and UX design. With a keen focus on programming languages, he crafts compelling content and designs …