JavaScript Promise.any()

Example

// Create a Promise
const myPromise1 = new Promise((resolve, reject) => {
  setTimeout(resolve, 200, "King");
});

// Create another Promise
const myPromise2 = new Promise((resolve, reject) => {
  setTimeout(resolve, 100, "Queen");
});

// Run when any promise fulfill
Promise.any([myPromise1, myPromise2]).then((x) => {
  myDisplay(x);
});
Try it Yourself »

Description

The Promise.any() method returns a single Promise from a list of promises, when any promise fulfill.


Syntax

Promise.any(iterable)

Parameters

iterable An Array of promises

Return Value

Type Description
Object A new Promise Object


Browser Support

Promise.any() is supported in all modern browsers since September 2020:

Chrome 85 Edge 85 Firefox 79 Safari 14 Opera 71
Aug 2019 Aug 2020 Jul 2020 Sep 2020 Sep 2020


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.