JavaScript Promise.race()

Definition and Usage

Promise.race() Methods return a Promise from a group of Promises, when the fastest Promise completes (resolved or rejected).

Instance

// 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");
});
// When the fastest Promise completes
Promise.race([myPromise1, myPromise2]).then((x) => {
  myDisplay(x);
});

Try It Yourself

Syntax

Promise.race(iterable)

Parameter

Parameter Description
iterable Promise Array.

Return Value

Type Description
Object New Promise Object.

Browser Support

Promise.race() Is a feature of ECMAScript 6 (ES6).

Since June 2017, ES6 (JavaScript 2015) is supported in all modern browsers:

Chrome Edge Firefox Safari Opera
Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 April 2017 June 2017 September 2016 June 2016

Promise.race() Not Supported by Internet Explorer.