非常简单。在javascript中,我需要检查字符串是否包含数组中包含的任何子字符串。
3 回答

largeQ
TA贡献2039条经验 获得超7个赞
var yourstring = 'tasty food'; // the string to check against
var substrings = ['foo','bar'],
length = substrings.length;
while(length--) {
if (yourstring.indexOf(substrings[length])!=-1) {
// one of the substrings is in yourstring
}
}

撒科打诨
TA贡献1934条经验 获得超2个赞
一线解决方案
substringsArray.some(substring=>yourBigString.includes(substring))
返回true\false子字符串exists\does'nt exist
需要ES6支持
添加回答
举报
0/150
提交
取消