ES6 filter an array with Regex

后端 未结 5 2022
清歌不尽
清歌不尽 2020-12-08 21:47

I\'m trying to filter an array that contains a bunch of urls. I need to return the urls that only contain the word \"contact\".

For example there is a link htt

5条回答
  •  遥遥无期
    2020-12-08 22:24

    var links = ["https://www.example.com/v1/contact-us/ca", "https://www.example.com/v1/contact-us/sanjose", "https://www.example.com/v1/meeting-us/ca"];
    
    var newlink = links.filter(function(link){
      return link.includes("contact")
    });
    
    console.log(newlink)
    

    Try this. It should work.

提交回复
热议问题