When should you use Promise.any in JavaScript?
When you want the first successful result from multiple sources. For example, fetching from multiple API endpoints or mirrors and using whichever responds first. If all fail, you get an AggregateError with all reasons.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Promise.any: Examples and Use Cases in JavaScript
It returns as soon as the first promise fulfills. It ignores rejections until all promises reject. If all reject, it rejects with an AggregateError containing all the rejection reasons.
Promise.race returns the first to settle (fulfilled or rejected). Promise.any returns the first to fulfill (ignores rejections). race can reject on the first rejection; any only rejects if all reject (with AggregateError).
An error type thrown by Promise.any when all promises reject. It has an errors property (an array of all individual rejection reasons). Check err instanceof AggregateError and access err.errors.
Still have questions?
Browse all our FAQs or reach out to our support team
