Reputation: 235
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.
Upvotes: 0
Views: 389
Reputation: 85897
You could use a regex:
if (/\/login\/auth|\/logout\//.test(referrer))
Upvotes: 1