Languages

JavaScript - match string against array of regular expressions

0 points
Asked by:
Dexter
660

Is there a way in JavaScript to match the string against the array of regular expressions?

I need something like this:

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can use Array some() method combined with RegExp test() to get a boolean value which you can later use in the if statement.

ES5 alternative:

 

References

  1. Array.prototype.some() - JavaScript | MDN
  2. RegExp.prototype.test() - JavaScript | MDN
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