Languages

JavaScript - equivalents of Python any() and all() functions?

0 points
Asked by:
Kevin
797

Are there any equivalents of Python any() and all() functions in JavaScript?

I need methods which can be applied on a list (array) as following:

  • any() - returns true if any element of the iterable is true. If the iterable is empty, returns false.
  • all() - returns true if all elements of the iterable are true, or if the iterable is empty.

Are there any equivalent built-in functions available in JavaScript?

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can implement a custom any() and all() methods using simple for loop combined with if statement.

Practical example

1. any() function:

2. all() function:

0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join