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

后端 未结 9 1841
北荒
北荒 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:56

    You're looking for the indexOf function:

    if (str.indexOf("are") >= 0){//Do stuff}
    

提交回复
热议问题