JavaScript Promise any() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Static method

Definition

Promise.any(promises) returns a promise that fulfills with the value of the first promise that fulfills. Rejections are skipped while there is still a chance of success. Only when every promise has rejected does it reject, with an AggregateError whose errors array holds all the reasons in input order. Think of it as "the first success wins".

Remember
Promise.any([a, b, c])  -> one promise

first FULFILLED value wins
rejections are ignored...
...unless ALL reject -> AggregateError
error.errors          -> every reason, input order
[]                    -> rejects (AggregateError)

Syntax

Call it on Promise with an array (or any iterable) of promises.

JavaScript
Promise.any(iterable)
const first = await Promise.any(iterable);
CallWhat it does
Promise.any([p1, p2, p3])Fulfill with the first value that arrives successfully.
error.errorsIn catch: the array of all rejection reasons.
Promise.any([])Rejects right away with an AggregateError.

A static method added in ES2021, together with the AggregateError class.

Library declarations
JavaScript
Promise.any(iterable)   // returns a Promise

// fulfills with: the value of the first promise that fulfills
// rejects with:  AggregateError (when all reject, or iterable is empty)
//                error.errors = [reason1, reason2, ...]

Parameters

ParameterDescription
iterableAn array (or other iterable) of promises. Plain values count as already fulfilled, so the first plain value wins.

Return Value

Return ValueDescription
PromiseFulfills with the first fulfilled value, or rejects with an AggregateError when no promise fulfills.

JavaScript Examples

Example 1 — Download from the Fastest Working Mirror

Three download servers are tried at once. The quickest one is down; the next quickest one wins.

JavaScript
function server(name, ms, works) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      console.log(name + (works ? ' answered' : ' failed'));
      if (works) resolve(name);
      else reject(new Error(name + ' is down'));
    }, ms);
  });
}

Promise.any([
  server('mirror-eu', 30, false),
  server('mirror-us', 90, true),
  server('mirror-asia', 60, true)
]).then((winner) => console.log('downloading from ' + winner));
Try It Yourself

How It Works

  1. The first answer is a failure. mirror-eu rejects after 30 ms. Promise.any notes the error and keeps waiting, because two servers are still pending.
  2. The first success wins. mirror-asia fulfills at 60 ms, so the result fulfills with 'mirror-asia' and the then callback starts the download.
  3. Later answers are ignored. mirror-us still answers at 90 ms, but the promise from Promise.any has already settled and does not change.

Example 2 — Every Promise Fails: AggregateError

If no promise fulfills, you get a single error that collects every reason.

JavaScript
const attempts = [
  Promise.reject(new Error('no wifi')),
  Promise.reject(new Error('no mobile data')),
  Promise.reject(new Error('no cable'))
];

Promise.any(attempts)
  .then((value) => console.log('connected: ' + value))
  .catch((error) => {
    console.log(error.name);
    console.log('reasons: ' + error.errors.length);
    error.errors.forEach((e) => console.log('- ' + e.message));
  });
Try It Yourself

How It Works

  1. Three rejected attempts. Every promise in attempts is already rejected with an error message we wrote ourselves.
  2. One combined error. With no success possible, Promise.any rejects with an AggregateError, so then is skipped and catch runs.
  3. Read the errors array. error.errors holds the three original reasons in input order, so you can show the user each one.

Example 3 — any() Compared with race(), Plus an Empty List

A quick failure and a slower success are given to both Promise.race() and Promise.any().

JavaScript
function later(ms, ok, label) {
  return new Promise((resolve, reject) => {
    setTimeout(() => (ok ? resolve(label) : reject(new Error(label))), ms);
  });
}

Promise.race([later(30, false, 'quick failure'), later(60, true, 'slow success')])
  .then((v) => console.log('race fulfilled: ' + v))
  .catch((e) => console.log('race rejected: ' + e.message));

Promise.any([later(30, false, 'quick failure'), later(60, true, 'slow success')])
  .then((v) => console.log('any fulfilled: ' + v));

Promise.any([]).catch((e) => console.log('empty list: ' + e.name));
Try It Yourself

How It Works

  1. An empty list fails at once. Promise.any([]) has nothing that could fulfill, so it rejects immediately and its catch prints before any timer fires.
  2. race() takes the first outcome. After 30 ms the quick failure settles first, so Promise.race rejects with it.
  3. any() waits for success. Promise.any skips that failure and fulfills at 60 ms with slow success.

Browser & Runtime Support

Promise.any() and AggregateError were added in ES2021.

✓ Widely available · ES2021

Promise.any()

Supported in all current browsers and in Node.js 15 and newer. The examples were run on Node.js 24.

Wide All current browsers
Google Chrome Chrome 85+
Supported
Mozilla Firefox Firefox 79+
Supported
Apple Safari Safari 14.1+
Supported
Microsoft Edge Edge 85+
Supported
Node.js Node.js 15+
Supported
Deno Recent versions
Supported
Internet Explorer No support
Not supported
Promise.any() Very good

Bottom line: Safe for current browsers. For browsers from before 2020, use a polyfill or Promise.allSettled() and pick the first fulfilled entry yourself.

Frequently Asked Questions

A promise that fulfills with the value of the first input promise that fulfills. Rejections are ignored as long as another promise can still succeed.
An error that wraps several errors. Promise.any rejects with one when every input rejects, and its errors property lists all the rejection reasons.
Promise.race settles with the first promise that settles, success or failure. Promise.any waits for the first success and only fails when everything fails.
It rejects right away with an AggregateError, because no promise can ever fulfill.
No. The other tasks keep running; their results are simply ignored once the first success has arrived.

Next: Promise.race()

Follow whichever promise settles first, whether it succeeds or fails.

race() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful