How to check if one of the strings from an array are in the URL/window.location.pathname

javascript, jquery

Solution

Use a for-loop for a linear search.

$(document).ready(function () {
    var checkURL = ['abc123', 'abc124', 'abc125'];

    for (var i = 0; i < checkURL.length; i++) {
        if(window.location.href.indexOf(checkURL[i]) > -1) {
            alert("your url contains the string "+checkURL[i]);
        }
    }
});

Problem

I have an array: ``` var checkURL = ['abc123', 'abc124', 'abc125']; ``` How can I check if one of the strings in the array exists in the window.location.pathname? I know individually I can use: ``` <script type="text/javascript"> $(document).ready(function () { if(window.location.href.indexOf("abc123") > -1) { alert("your url contains the string abc123"); } }); </script> ```

Original source