Check pathname for Array












0















i got a question:



This code snippet works great:



$(document).ready(function(){         
var pathname = window.location.pathname;
if(pathname.indexOf( 'word1' ) > -1){
// do something
}
});


But if i want to check for array of word´s it doesnt work:



$(document).ready(function(){         
var myArray1 = new Array( "word1","word2","word3","word4" );
var pathname = window.location.pathname;
if(pathname.indexOf( myArray1 ) > -1){
// never executed! why?
}
});


Anybody could help with this problem? Greetings!










share|improve this question




















  • 1





    if (myArray1.indexOf(pathname) != -1) { ... }.

    – Ja͢ck
    Mar 2 '14 at 23:13
















0















i got a question:



This code snippet works great:



$(document).ready(function(){         
var pathname = window.location.pathname;
if(pathname.indexOf( 'word1' ) > -1){
// do something
}
});


But if i want to check for array of word´s it doesnt work:



$(document).ready(function(){         
var myArray1 = new Array( "word1","word2","word3","word4" );
var pathname = window.location.pathname;
if(pathname.indexOf( myArray1 ) > -1){
// never executed! why?
}
});


Anybody could help with this problem? Greetings!










share|improve this question




















  • 1





    if (myArray1.indexOf(pathname) != -1) { ... }.

    – Ja͢ck
    Mar 2 '14 at 23:13














0












0








0


1






i got a question:



This code snippet works great:



$(document).ready(function(){         
var pathname = window.location.pathname;
if(pathname.indexOf( 'word1' ) > -1){
// do something
}
});


But if i want to check for array of word´s it doesnt work:



$(document).ready(function(){         
var myArray1 = new Array( "word1","word2","word3","word4" );
var pathname = window.location.pathname;
if(pathname.indexOf( myArray1 ) > -1){
// never executed! why?
}
});


Anybody could help with this problem? Greetings!










share|improve this question
















i got a question:



This code snippet works great:



$(document).ready(function(){         
var pathname = window.location.pathname;
if(pathname.indexOf( 'word1' ) > -1){
// do something
}
});


But if i want to check for array of word´s it doesnt work:



$(document).ready(function(){         
var myArray1 = new Array( "word1","word2","word3","word4" );
var pathname = window.location.pathname;
if(pathname.indexOf( myArray1 ) > -1){
// never executed! why?
}
});


Anybody could help with this problem? Greetings!







javascript jquery






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 2 '14 at 23:08









Felix Kling

554k128862919




554k128862919










asked Mar 2 '14 at 23:03









user3297073user3297073

598




598








  • 1





    if (myArray1.indexOf(pathname) != -1) { ... }.

    – Ja͢ck
    Mar 2 '14 at 23:13














  • 1





    if (myArray1.indexOf(pathname) != -1) { ... }.

    – Ja͢ck
    Mar 2 '14 at 23:13








1




1





if (myArray1.indexOf(pathname) != -1) { ... }.

– Ja͢ck
Mar 2 '14 at 23:13





if (myArray1.indexOf(pathname) != -1) { ... }.

– Ja͢ck
Mar 2 '14 at 23:13












6 Answers
6






active

oldest

votes


















1














jQuery has a built in method for that, $.inArray :



$(document).ready(function(){         

var pathname = window.location.pathname;

if ( $.inArray(pathname, ["word1","word2","word3","word4"] ) != -1 ) {

// do stuff

}
});


then there's regex



$(document).ready(function(){         
if ( /(word1|word2|word3|word4)/.test(window.location.pathname) ) {
// do stuff
}
});





share|improve this answer


























  • If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

    – TypingTurtle
    Mar 2 '14 at 23:13











  • But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

    – ocanal
    Mar 2 '14 at 23:22





















0














If you want to test pathname against an array of values, I suggest looping. You cannot send in an array object as an argument to the indexOf() method. You can only send strings.



$(document).ready(function(){         
var myArray1 = new Array( "word1","word2","word3","word4" );
var pathname = window.location.pathname;
for(stringy in myArray1){
if(pathname.indexOf( stringy ) > -1){
console.log('Match Found');
}
}
});


Look here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf






share|improve this answer
























  • Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

    – Felix Kling
    Mar 2 '14 at 23:09





















0














You could use jQuery.grep() for this:



if ($.grep(myArray1, function(word) {
return pathname.indexOf(word) != -1;
})) {
// do something
}


Or, use native functions:



if (myArray1.some(function(word) {
return pathname.indexOf(word) != -1;
})) {
// do something
}





share|improve this answer































    0














    indexOf looks for occurrences of a given string in another string. So you can't invoke it with an array as parameter. You must invoke it several times, each one with a string as parameter.



    $(document).ready(function(){         
    var myArray1 = new Array( "word1","word2","word3","word4" );
    var pathname = window.location.pathname;
    for(var i=0; i<myArray1.length; i++) {
    if(pathname.indexOf( myArray1[i] ) > -1){
    // will be executed
    }
    }
    });





    share|improve this answer

































      0














      string.indexOf doesn't take array as a parameter, you should handle it yourself,



      Ok I will make it a little bit different, you can also do this with Regex,



      $(document).ready(function(){         
      var myArray1 = new Array( "word1","word2","word3","word4" );
      var pathname = window.location.pathname;
      if (pathname.match(new RegExp(myArray1.join("|")))) {
      // yes, there is at least one match.
      }
      });


      I don't know whether if you want it to match all words in the array.






      share|improve this answer


























      • Use a normal for loop to iterate over arrays (not for...in).

        – Felix Kling
        Mar 2 '14 at 23:09













      • @FelixKling Is a for(string in array) fine?

        – turnt
        Mar 2 '14 at 23:09











      • @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

        – Felix Kling
        Mar 2 '14 at 23:10





















      0














      I made a way to test n quantities of pathnames.



      import pathToRegexp from 'path-to-regexp';

      const ALLOWED_PATHS = [
      'test',
      'test/:param'
      ]

      const allowed = ALLOWED_PATHS.map((path) => {
      const regex = pathToRegexp(path)
      return regex.test(window.location.pathname);
      });

      if(allowed.some(Boolean)) {
      // Match
      } else {
      // Not Match
      }

      ...


      Hope this helps you!






      share|improve this answer

























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22134886%2fcheck-pathname-for-array%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        6 Answers
        6






        active

        oldest

        votes








        6 Answers
        6






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        jQuery has a built in method for that, $.inArray :



        $(document).ready(function(){         

        var pathname = window.location.pathname;

        if ( $.inArray(pathname, ["word1","word2","word3","word4"] ) != -1 ) {

        // do stuff

        }
        });


        then there's regex



        $(document).ready(function(){         
        if ( /(word1|word2|word3|word4)/.test(window.location.pathname) ) {
        // do stuff
        }
        });





        share|improve this answer


























        • If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

          – TypingTurtle
          Mar 2 '14 at 23:13











        • But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

          – ocanal
          Mar 2 '14 at 23:22


















        1














        jQuery has a built in method for that, $.inArray :



        $(document).ready(function(){         

        var pathname = window.location.pathname;

        if ( $.inArray(pathname, ["word1","word2","word3","word4"] ) != -1 ) {

        // do stuff

        }
        });


        then there's regex



        $(document).ready(function(){         
        if ( /(word1|word2|word3|word4)/.test(window.location.pathname) ) {
        // do stuff
        }
        });





        share|improve this answer


























        • If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

          – TypingTurtle
          Mar 2 '14 at 23:13











        • But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

          – ocanal
          Mar 2 '14 at 23:22
















        1












        1








        1







        jQuery has a built in method for that, $.inArray :



        $(document).ready(function(){         

        var pathname = window.location.pathname;

        if ( $.inArray(pathname, ["word1","word2","word3","word4"] ) != -1 ) {

        // do stuff

        }
        });


        then there's regex



        $(document).ready(function(){         
        if ( /(word1|word2|word3|word4)/.test(window.location.pathname) ) {
        // do stuff
        }
        });





        share|improve this answer















        jQuery has a built in method for that, $.inArray :



        $(document).ready(function(){         

        var pathname = window.location.pathname;

        if ( $.inArray(pathname, ["word1","word2","word3","word4"] ) != -1 ) {

        // do stuff

        }
        });


        then there's regex



        $(document).ready(function(){         
        if ( /(word1|word2|word3|word4)/.test(window.location.pathname) ) {
        // do stuff
        }
        });






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 2 '14 at 23:16

























        answered Mar 2 '14 at 23:11









        adeneoadeneo

        263k19282312




        263k19282312













        • If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

          – TypingTurtle
          Mar 2 '14 at 23:13











        • But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

          – ocanal
          Mar 2 '14 at 23:22





















        • If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

          – TypingTurtle
          Mar 2 '14 at 23:13











        • But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

          – ocanal
          Mar 2 '14 at 23:22



















        If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

        – TypingTurtle
        Mar 2 '14 at 23:13





        If you wanna get fancy you can do the !!~ pattern for any indexOf type functions: if(!!~$.inArray(pathname, [...])) {

        – TypingTurtle
        Mar 2 '14 at 23:13













        But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

        – ocanal
        Mar 2 '14 at 23:22







        But $.inArray("word1 word2", ["word1","word2","word3","word4"]) won't match, is that what OP wants?

        – ocanal
        Mar 2 '14 at 23:22















        0














        If you want to test pathname against an array of values, I suggest looping. You cannot send in an array object as an argument to the indexOf() method. You can only send strings.



        $(document).ready(function(){         
        var myArray1 = new Array( "word1","word2","word3","word4" );
        var pathname = window.location.pathname;
        for(stringy in myArray1){
        if(pathname.indexOf( stringy ) > -1){
        console.log('Match Found');
        }
        }
        });


        Look here:
        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf






        share|improve this answer
























        • Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

          – Felix Kling
          Mar 2 '14 at 23:09


















        0














        If you want to test pathname against an array of values, I suggest looping. You cannot send in an array object as an argument to the indexOf() method. You can only send strings.



        $(document).ready(function(){         
        var myArray1 = new Array( "word1","word2","word3","word4" );
        var pathname = window.location.pathname;
        for(stringy in myArray1){
        if(pathname.indexOf( stringy ) > -1){
        console.log('Match Found');
        }
        }
        });


        Look here:
        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf






        share|improve this answer
























        • Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

          – Felix Kling
          Mar 2 '14 at 23:09
















        0












        0








        0







        If you want to test pathname against an array of values, I suggest looping. You cannot send in an array object as an argument to the indexOf() method. You can only send strings.



        $(document).ready(function(){         
        var myArray1 = new Array( "word1","word2","word3","word4" );
        var pathname = window.location.pathname;
        for(stringy in myArray1){
        if(pathname.indexOf( stringy ) > -1){
        console.log('Match Found');
        }
        }
        });


        Look here:
        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf






        share|improve this answer













        If you want to test pathname against an array of values, I suggest looping. You cannot send in an array object as an argument to the indexOf() method. You can only send strings.



        $(document).ready(function(){         
        var myArray1 = new Array( "word1","word2","word3","word4" );
        var pathname = window.location.pathname;
        for(stringy in myArray1){
        if(pathname.indexOf( stringy ) > -1){
        console.log('Match Found');
        }
        }
        });


        Look here:
        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 2 '14 at 23:07









        turntturnt

        2,30351735




        2,30351735













        • Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

          – Felix Kling
          Mar 2 '14 at 23:09





















        • Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

          – Felix Kling
          Mar 2 '14 at 23:09



















        Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

        – Felix Kling
        Mar 2 '14 at 23:09







        Use a normal for loop to iterate over arrays (not for...in). stringy doesn't even refer to the element in the array, but the index.

        – Felix Kling
        Mar 2 '14 at 23:09













        0














        You could use jQuery.grep() for this:



        if ($.grep(myArray1, function(word) {
        return pathname.indexOf(word) != -1;
        })) {
        // do something
        }


        Or, use native functions:



        if (myArray1.some(function(word) {
        return pathname.indexOf(word) != -1;
        })) {
        // do something
        }





        share|improve this answer




























          0














          You could use jQuery.grep() for this:



          if ($.grep(myArray1, function(word) {
          return pathname.indexOf(word) != -1;
          })) {
          // do something
          }


          Or, use native functions:



          if (myArray1.some(function(word) {
          return pathname.indexOf(word) != -1;
          })) {
          // do something
          }





          share|improve this answer


























            0












            0








            0







            You could use jQuery.grep() for this:



            if ($.grep(myArray1, function(word) {
            return pathname.indexOf(word) != -1;
            })) {
            // do something
            }


            Or, use native functions:



            if (myArray1.some(function(word) {
            return pathname.indexOf(word) != -1;
            })) {
            // do something
            }





            share|improve this answer













            You could use jQuery.grep() for this:



            if ($.grep(myArray1, function(word) {
            return pathname.indexOf(word) != -1;
            })) {
            // do something
            }


            Or, use native functions:



            if (myArray1.some(function(word) {
            return pathname.indexOf(word) != -1;
            })) {
            // do something
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 2 '14 at 23:22









            Ja͢ckJa͢ck

            145k27210267




            145k27210267























                0














                indexOf looks for occurrences of a given string in another string. So you can't invoke it with an array as parameter. You must invoke it several times, each one with a string as parameter.



                $(document).ready(function(){         
                var myArray1 = new Array( "word1","word2","word3","word4" );
                var pathname = window.location.pathname;
                for(var i=0; i<myArray1.length; i++) {
                if(pathname.indexOf( myArray1[i] ) > -1){
                // will be executed
                }
                }
                });





                share|improve this answer






























                  0














                  indexOf looks for occurrences of a given string in another string. So you can't invoke it with an array as parameter. You must invoke it several times, each one with a string as parameter.



                  $(document).ready(function(){         
                  var myArray1 = new Array( "word1","word2","word3","word4" );
                  var pathname = window.location.pathname;
                  for(var i=0; i<myArray1.length; i++) {
                  if(pathname.indexOf( myArray1[i] ) > -1){
                  // will be executed
                  }
                  }
                  });





                  share|improve this answer




























                    0












                    0








                    0







                    indexOf looks for occurrences of a given string in another string. So you can't invoke it with an array as parameter. You must invoke it several times, each one with a string as parameter.



                    $(document).ready(function(){         
                    var myArray1 = new Array( "word1","word2","word3","word4" );
                    var pathname = window.location.pathname;
                    for(var i=0; i<myArray1.length; i++) {
                    if(pathname.indexOf( myArray1[i] ) > -1){
                    // will be executed
                    }
                    }
                    });





                    share|improve this answer















                    indexOf looks for occurrences of a given string in another string. So you can't invoke it with an array as parameter. You must invoke it several times, each one with a string as parameter.



                    $(document).ready(function(){         
                    var myArray1 = new Array( "word1","word2","word3","word4" );
                    var pathname = window.location.pathname;
                    for(var i=0; i<myArray1.length; i++) {
                    if(pathname.indexOf( myArray1[i] ) > -1){
                    // will be executed
                    }
                    }
                    });






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 2 '15 at 20:06









                    GitaarLAB

                    11.7k74470




                    11.7k74470










                    answered Mar 2 '14 at 23:11









                    Pascal Le MerrerPascal Le Merrer

                    4,4441328




                    4,4441328























                        0














                        string.indexOf doesn't take array as a parameter, you should handle it yourself,



                        Ok I will make it a little bit different, you can also do this with Regex,



                        $(document).ready(function(){         
                        var myArray1 = new Array( "word1","word2","word3","word4" );
                        var pathname = window.location.pathname;
                        if (pathname.match(new RegExp(myArray1.join("|")))) {
                        // yes, there is at least one match.
                        }
                        });


                        I don't know whether if you want it to match all words in the array.






                        share|improve this answer


























                        • Use a normal for loop to iterate over arrays (not for...in).

                          – Felix Kling
                          Mar 2 '14 at 23:09













                        • @FelixKling Is a for(string in array) fine?

                          – turnt
                          Mar 2 '14 at 23:09











                        • @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

                          – Felix Kling
                          Mar 2 '14 at 23:10


















                        0














                        string.indexOf doesn't take array as a parameter, you should handle it yourself,



                        Ok I will make it a little bit different, you can also do this with Regex,



                        $(document).ready(function(){         
                        var myArray1 = new Array( "word1","word2","word3","word4" );
                        var pathname = window.location.pathname;
                        if (pathname.match(new RegExp(myArray1.join("|")))) {
                        // yes, there is at least one match.
                        }
                        });


                        I don't know whether if you want it to match all words in the array.






                        share|improve this answer


























                        • Use a normal for loop to iterate over arrays (not for...in).

                          – Felix Kling
                          Mar 2 '14 at 23:09













                        • @FelixKling Is a for(string in array) fine?

                          – turnt
                          Mar 2 '14 at 23:09











                        • @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

                          – Felix Kling
                          Mar 2 '14 at 23:10
















                        0












                        0








                        0







                        string.indexOf doesn't take array as a parameter, you should handle it yourself,



                        Ok I will make it a little bit different, you can also do this with Regex,



                        $(document).ready(function(){         
                        var myArray1 = new Array( "word1","word2","word3","word4" );
                        var pathname = window.location.pathname;
                        if (pathname.match(new RegExp(myArray1.join("|")))) {
                        // yes, there is at least one match.
                        }
                        });


                        I don't know whether if you want it to match all words in the array.






                        share|improve this answer















                        string.indexOf doesn't take array as a parameter, you should handle it yourself,



                        Ok I will make it a little bit different, you can also do this with Regex,



                        $(document).ready(function(){         
                        var myArray1 = new Array( "word1","word2","word3","word4" );
                        var pathname = window.location.pathname;
                        if (pathname.match(new RegExp(myArray1.join("|")))) {
                        // yes, there is at least one match.
                        }
                        });


                        I don't know whether if you want it to match all words in the array.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited May 10 '18 at 16:37









                        Ivan

                        5,33331341




                        5,33331341










                        answered Mar 2 '14 at 23:08









                        ocanalocanal

                        9,2191556109




                        9,2191556109













                        • Use a normal for loop to iterate over arrays (not for...in).

                          – Felix Kling
                          Mar 2 '14 at 23:09













                        • @FelixKling Is a for(string in array) fine?

                          – turnt
                          Mar 2 '14 at 23:09











                        • @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

                          – Felix Kling
                          Mar 2 '14 at 23:10





















                        • Use a normal for loop to iterate over arrays (not for...in).

                          – Felix Kling
                          Mar 2 '14 at 23:09













                        • @FelixKling Is a for(string in array) fine?

                          – turnt
                          Mar 2 '14 at 23:09











                        • @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

                          – Felix Kling
                          Mar 2 '14 at 23:10



















                        Use a normal for loop to iterate over arrays (not for...in).

                        – Felix Kling
                        Mar 2 '14 at 23:09







                        Use a normal for loop to iterate over arrays (not for...in).

                        – Felix Kling
                        Mar 2 '14 at 23:09















                        @FelixKling Is a for(string in array) fine?

                        – turnt
                        Mar 2 '14 at 23:09





                        @FelixKling Is a for(string in array) fine?

                        – turnt
                        Mar 2 '14 at 23:09













                        @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

                        – Felix Kling
                        Mar 2 '14 at 23:10







                        @Cygwinnian: In general, no: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/….

                        – Felix Kling
                        Mar 2 '14 at 23:10













                        0














                        I made a way to test n quantities of pathnames.



                        import pathToRegexp from 'path-to-regexp';

                        const ALLOWED_PATHS = [
                        'test',
                        'test/:param'
                        ]

                        const allowed = ALLOWED_PATHS.map((path) => {
                        const regex = pathToRegexp(path)
                        return regex.test(window.location.pathname);
                        });

                        if(allowed.some(Boolean)) {
                        // Match
                        } else {
                        // Not Match
                        }

                        ...


                        Hope this helps you!






                        share|improve this answer






























                          0














                          I made a way to test n quantities of pathnames.



                          import pathToRegexp from 'path-to-regexp';

                          const ALLOWED_PATHS = [
                          'test',
                          'test/:param'
                          ]

                          const allowed = ALLOWED_PATHS.map((path) => {
                          const regex = pathToRegexp(path)
                          return regex.test(window.location.pathname);
                          });

                          if(allowed.some(Boolean)) {
                          // Match
                          } else {
                          // Not Match
                          }

                          ...


                          Hope this helps you!






                          share|improve this answer




























                            0












                            0








                            0







                            I made a way to test n quantities of pathnames.



                            import pathToRegexp from 'path-to-regexp';

                            const ALLOWED_PATHS = [
                            'test',
                            'test/:param'
                            ]

                            const allowed = ALLOWED_PATHS.map((path) => {
                            const regex = pathToRegexp(path)
                            return regex.test(window.location.pathname);
                            });

                            if(allowed.some(Boolean)) {
                            // Match
                            } else {
                            // Not Match
                            }

                            ...


                            Hope this helps you!






                            share|improve this answer















                            I made a way to test n quantities of pathnames.



                            import pathToRegexp from 'path-to-regexp';

                            const ALLOWED_PATHS = [
                            'test',
                            'test/:param'
                            ]

                            const allowed = ALLOWED_PATHS.map((path) => {
                            const regex = pathToRegexp(path)
                            return regex.test(window.location.pathname);
                            });

                            if(allowed.some(Boolean)) {
                            // Match
                            } else {
                            // Not Match
                            }

                            ...


                            Hope this helps you!







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 20 '18 at 5:36

























                            answered Nov 7 '18 at 4:21









                            slorenzoslorenzo

                            1,9192038




                            1,9192038






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22134886%2fcheck-pathname-for-array%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                鏡平學校

                                ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                                Why https connections are so slow when debugging (stepping over) in Java?