开发者

String contains another string [duplicate]

开发者 https://www.devze.com 2023-03-08 11:13 出处:网络
This question already has answers here: How to check whether a string contains a substring in JavaScript?
This question already has answers here: How to check whether a string contains a substring in JavaScript? (3 answers) Closed 9 years ago.

How can I check if a string c开发者_高级运维ontains another string instead of using "==" to compare the whole string?

Regards


You can use .indexOf():

if(str.indexOf(substr) > -1) {

}
0

精彩评论

暂无评论...
验证码 换一张
取 消