# Promise.any()

> The `Promise.any()` static JS method takes an iterable of `Promise` objects and returns one `Promise` object that resolves with the first fulfilled value.

## How do I get the first successful promise with Promise.any()?

The static method that takes an iterable of promises and returns a `Promise` that fulfills with the value of the first promise that fulfills. If all of them reject, the returned promise rejects with an `AggregateError`.

- Topic: Promise
- Type: method
- Browser support: Chrome 85+, Chrome Android 85+, Edge 85+, Firefox 79+, Firefox Android 79+, Safari 14+, Safari iOS 14+

## Example

Wrong:

```js
const res = await Promise.race([
  fetch(primaryUrl),
  fetch(mirrorUrl),
]);
```

Right:

```js
const res = await Promise.any([
  fetch(primaryUrl),
  fetch(mirrorUrl),
]);
```

`race()` rejects if the fastest request fails; `any()` waits for the first request that succeeds.

## Common mistakes

- Using `Promise.race()` for fallbacks and failing whenever the fastest source errors.
- Logging only the message of the `AggregateError` and missing the real causes.

## Key points

- Failures from `Promise.any()` are read from `error.errors`, the array inside the `AggregateError`.
- `Promise.any()` is used for the first success; `Promise.race()` only when the first settled result, even a failure, is wanted.
- Requests that are no longer needed after a winner are aborted with `AbortController`.

## Interview questions

### Promise.any vs Promise.race: what is the difference?

`Promise.any()` fulfills with the first success and rejects only if all fail. `Promise.race()` settles with whichever promise settles first, success or failure.

### What does `Promise.any()` do with an empty array?

It rejects right away with an `AggregateError` whose `errors` array is empty.

## Related cards

- [AggregateError](https://wonderium.dev/js/aggregate-error.md)
- [Promise.race()](https://wonderium.dev/js/promise-race.md)
- [Promise.all()](https://wonderium.dev/js/promise-all.md)
- [AbortController](https://wonderium.dev/js/abort-controller.md)
- [Promise](https://wonderium.dev/js/promise.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/promise-any
- Last updated: 2026-11-25
