假设我的数组是 ["abcdefg", "hijklmnop"] 并且我正在查看“mnop”是否是该数组的一部分。我如何使用 JavaScript 方法来做到这一点?
我尝试了这个,但它不起作用:
var array= ["abcdefg", "hijklmnop"];
console.log(array.indexOf("mnop")); //-1 since it does not find it in the string
最佳答案
var array= ["abcdefg", "hijklmnop"];
var newArray = array.filter(function(val) {
return val.indexOf("mnop") !== -1
})
console.log(newArray)
关于javascript - 有没有一个javascript方法可以在字符串数组中查找子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38798581/