I have three urls I have split down to keywords. In JavaScript I want to see if two of these Urls match two given keywords. Both keywords have to match two of the url’s for the code to proceed but I can’t think of a short way to do it.
I have tried…
if (url1 || url2 || url3 === "keyword1" && "keyword2") {
....
}
And
if (url1 || url2 || url3 === "keyword1" && url1 || url2 || url3 == "keyword2") {
....
}
This is as far as I got. The problem is, it returns a match for just one of the keywords instead of only returning a match for both . I have a feeling that not ruling out the first match is causing the second to match the same variable. I hope this makes sense!
Can anybody help me?
If you combine all url values into a single array you can use
.indexOf()(the page includes a compatible version if a browser doesn’t support this relatively new method).