JavaScript/jQuery - How to check if a string contain specific words

后端 未结 9 1867
北荒
北荒 2020-12-03 10:14
$a = \'how are you\';
if (strpos($a,\'are\') !== false) {
    echo \'true\';
}

In PHP, we can use the code above to check if a string contain speci

9条回答
  •  悲哀的现实
    2020-12-03 10:48

    You might wanna use include method in JS.

    var sentence = "This is my line";
    console.log(sentence.includes("my"));
    //returns true if substring is present.
    

    PS: includes is case sensitive.

提交回复
热议问题