Skip to main content

Command Palette

Search for a command to run...

Using Promise.any() in JavaScript

Updated
โ€ข1 min read
Using Promise.any() in JavaScript
P

Hi everyone ๐Ÿ‘‹

I am Palash, a passionate programmer & front-end developer. I like to share HTML, CSS, JavaScript and web development tips & tricks and try to explain them in a simple manner.

Happy Coding!

In this video, I'll discuss

  • What is Promise.any() method?
  • Syntax
  • What parameters does this method accept?
  • What does it return?
  • and finally What is the main difference between Promise.any() & Promise.race() methods?

I am going to explain all of these points using lots of examples so that you can clearly understand it and then maybe you can start using it in your own projects based on your use cases.

Description

Promise.any() takes an iterable of Promise objects and, as soon as one of the promises in the iterable fulfills, returns a single promise that resolves with the value from that promise. This method is useful for returning the first promise that fulfills.

Syntax

Promise.any(iterable);

Parameters

iterable - an iterable object, such as an Array.

Please check out this video where all the points are explained in full details:


Wrap Up

I hope you will find this video useful and learn something new in the process. If you want to learn more HTML, CSS, JavaScript and web development tips & tricks, please make sure to subscribe on YouTube!

C

Thanks for sharing.

1
P

You're very welcome. ๐Ÿ˜Š

1
A

Screenshot from 2021-02-21 15-42-05.png

Glad to see it is supported by Major browsers.

2
P

Agreed. Thanks for mentioning this point!

1

More from this blog

C

Code with Palash

11 posts

Hi ๐Ÿ‘‹ I am Palash, a passionate programmer & front-end developer. I like to share HTML, CSS, JavaScript and web development tips & tricks and try to explain them in a simple manner. Happy Coding!