This question already has an answer here:(这个问题在这里已有答案:)
I need to check whether a string contains another string or not?(我需要检查一个字符串是否包含另一个字符串?)
var str1 = "ABCDEFGHIJKLMNOP"; var str2 = "DEFG";
You can use javascript's indexOf function.(你可以使用javascript的indexOf函数。)
var str1 = "ABCDEFGHIJKLMNOP"; var str2 = "DEFG"; if(str1.indexOf(str2) != -1){ console.log(str2 + " found"); }
1.4m articles
1.4m replys
5 comments
56.9k users