0

I am trying to match if a string contains any of the following values and I was wondering if there is a way to do it in JS with out indexOf or includes with multiple || ?

Eg:

    const referrer = "www.google.com/login/auth";
    const loginRoute = "/login/auth";
    const logoutRoute = "/logout/";
    if(referrer.includes(loginRoute) || referrer.includes(logoutRoute)) {
       //do something
    }

is there any other way of doing this as I am trying to avoid multiple || conditions? in my implementation I have to check with five different URIs.

tsinat
  • 235
  • 1
  • 3
  • 16
  • Possible duplicate of [How to search for multiple texts in a string, using java script?](https://stackoverflow.com/questions/16851094/how-to-search-for-multiple-texts-in-a-string-using-java-script) – Heretic Monkey Dec 10 '18 at 18:25

1 Answers1

1

You could use a regex:

if (/\/login\/auth|\/logout\//.test(referrer))
melpomene
  • 84,125
  • 8
  • 85
  • 148