开发者

Is there a javascript method to find out if a string is part of another string?

开发者 https://www.devze.com 2023-03-22 07:46 出处:网络
I need to find out if one string is in another and return true or false, or something similar. just remembered having read someth开发者_运维技巧ing about indexof returning something like -1 if it doe

I need to find out if one string is in another and return true or false, or something similar.

just remembered having read someth开发者_运维技巧ing about indexof returning something like -1 if it doesn't find something?


Use the indexOf function of String:

var str = "something";
var other = "thi";
if (str.indexOf(other) != -1) {
    // other is a part of the original string.
}
0

精彩评论

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