简体   繁体   中英

Check whether url from api data contain a particular string

I have my JSON data from API stored in map now one of its data is named with URL and contains URL of the sites I have to check whether the URL contains a particular string or not so that I can apply different styling to the div on HTML

let x = `${ values.url }`;
      if (x.contains("codeforces")) {
        console.log("Yes");
      }

I am getting error while using this:

控制台错误

Please help me with this.

I think you want to use includes function. There is no function called contains

let x = values.url;
  if (x.includes("codeforces")) {
    console.log("Yes");
  }

Let me know if it helps:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM