Js judges whether Chinese characters appear in the range and how to write them.

provincelist(newVal){
        var eidtCty = window.localStorage.citycode;
        var newCty = JSON.stringify(eidtCty.substring(0,eidtCty.length-1));
        newVal.forEach((v,i)=>{
          var forCty = JSON.stringify(v.provinceName)
          if(forCty.indexOf(newCty) != -1){
            console.log(123)
            /* this.isdialog = true;
            this.alertarea() */
          }
        })
      }

forCty is
"Beijing"
"Hebei"
"Shanghai"
"Shandong"
newCty is
"Beijing"

the demand is that the city in newCty performs the operation if it is not within the scope of forCty, and if it does not perform the operation within the scope, how to judge the boss for help

Jun.15,2022

just change "! =-1" to "=-1", if you read it correctly.

if(forCty.indexOf(newCty) == -1){
            console.log(123)
            /* this.isdialog = true;
            this.alertarea() */
          }

besides indexOf, you can also use inculdes

if (forCty.includes(newCty)) {
  // ...
}
Menu