开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜