Promise

Promise.any

Takes an iterable of promises and returns a promise that resolves as soon as any of the promises fulfills, with the value of the first fulfilled promise

Syntax

JavaScript
Promise.any(iterable)

Parameters

ParameterTypeDescription
iterableIterable<Promise<T>>An iterable of promises

Return Value

A Promise that resolves with the first fulfilled value, or rejects with AggregateError

Examples

Basic Usage
const promises = [
  Promise.reject('a'),
  Promise.resolve('b'),
  Promise.resolve('c'),
];
const first = await Promise.any(promises);
console.log(first); // 'b'
Practical Example
async function fastestMirror(urls: string[]) {
  return Promise.any(urls.map(url => fetch(url)));
}
Advanced Usage
// All reject => AggregateError
try {
  await Promise.any([Promise.reject(1), Promise.reject(2)]);
} catch (err) {
  console.log(err instanceof AggregateError); // true
}

Understanding Promise.any

The Promise.any method in JavaScript takes an iterable of promises and returns a promise that resolves as soon as any of the promises fulfills, with the value of the first fulfilled promise. It belongs to the Promise object and is one of the most widely used methods for working with promise values in modern JavaScript and TypeScript applications.

The method signature is Promise.any(iterable). It accepts 1 parameter: iterable. When called, it returns a promise that resolves with the first fulfilled value, or rejects with aggregateerror. Understanding when and how to use any() helps you write more expressive, readable code.

Common use cases for Promise.any include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like promise-race, promise-all, promise-allsettled, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Promise.any is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Promise Methods

Other methods in the Promise object

Related Tools

More Promise Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.