0

I have this code below but I want it to stop going through the loop once it finds one or more strings. That way the div will still be hidden.

Thanks for the help!

var checkURL = ["fish","dog","cat","bird"];

for (var i = 0; i < checkURL.length; i++) {
    if(window.location.href.indexOf(checkURL[i]) > -1) {
        // keep div hidden
    } else {
        // show div
    }
}
user2428993
  • 323
  • 1
  • 10
  • Possible duplicate of [How to check if a string contains text from an array of substrings in JavaScript?](https://stackoverflow.com/questions/5582574/how-to-check-if-a-string-contains-text-from-an-array-of-substrings-in-javascript) – Heretic Monkey Jul 11 '18 at 19:43

1 Answers1

0
break;

Will get you out of the loop once you've found what you needed.

Luke
  • 648
  • 7
  • 15