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
Promise.any(iterable)Parameters
| Parameter | Type | Description |
|---|---|---|
| iterable | Iterable<Promise<T>> | An iterable of promises |
Return Value
A Promise that resolves with the first fulfilled value, or rejects with AggregateError
Examples
const promises = [
Promise.reject('a'),
Promise.resolve('b'),
Promise.resolve('c'),
];
const first = await Promise.any(promises);
console.log(first); // 'b'async function fastestMirror(urls: string[]) {
return Promise.any(urls.map(url => fetch(url)));
}// 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
Promise.raceTakes an iterable of promises and returns a promise that settles with the eventual state of the first promise that settles
Promise.allTakes an iterable of promises and returns a single promise that resolves when all of the input promises have resolved, or rejects when any input promise rejects
Promise.allSettledTakes an iterable of promises and returns a promise that resolves after all promises have settled (fulfilled or rejected)
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.