Javascript 有没有办法(使用Lodash或下划线)查看字符串数组中的字符串是否包含另一个数组中的子字符串?

Javascript 有没有办法(使用Lodash或下划线)查看字符串数组中的字符串是否包含另一个数组中的子字符串?,javascript,underscore.js,lodash,Javascript,Underscore.js,Lodash,我有一个字符串数组: ["General election 2017: No cut to UK aid spending, says May", "Paris Champs Elysees attack gunman named as Karim Cheurfi", "William and Kate surprise Radio 1 visit", "South Africa bus crash 'kills at least 19 children'", "Len McCluskey re

我有一个字符串数组:

["General election 2017: No cut to UK aid spending, says May", "Paris Champs Elysees attack gunman named as Karim Cheurfi", "William and Kate surprise Radio 1 visit", "South Africa bus crash 'kills at least 19 children'", "Len McCluskey re-elected as Unite general secretary", "Cleethorpes car crash captured on CCTV", "Adam Johnson prison video investigated", "Julian Assange's arrest a 'priority' for US attorney general", "Shrewsbury trust warned over baby heart monitoring in 2007", "High heels row: Petition for work dress code law rejected"]
我想看看上面数组中的任何字符串是否有来自另一个数组的子字符串:

["South Africa", "United States"]
如果有,请执行xyz

我尝试过使用0.difference(lodash)和0.intersection(下划线),但我认为它不会比较子字符串的字符串

另外,很抱歉这些疯狂的数组字符串——它们是来自返回的JSON的新闻文章

谢谢你的帮助…

if(交叉点(arr,check).length>0){
//做点什么
}否则{
//做点什么
}
if(交叉点(arr,check).length>0){
//做点什么
}否则{
//做点什么

}
这里有一个单行程序来实现这一点(使用ES6 arrow函数,因此如果不进行传输,可能需要将其重写为常规的
函数(){}
)。您根本不需要
lodash

var a = ["General election 2017: No cut to UK aid spending, says May", "Paris Champs Elysees attack gunman named as Karim Cheurfi", "William and Kate surprise Radio 1 visit", "South Africa bus crash 'kills at least 19 children'", "Len McCluskey re-elected as Unite general secretary", "Cleethorpes car crash captured on CCTV", "Adam Johnson prison video investigated", "Julian Assange's arrest a 'priority' for US attorney general", "Shrewsbury trust warned over baby heart monitoring in 2007", "High heels row: Petition for work dress code law rejected"];
var b = ["South Africa", "United States"];
var match = a.filter(source => b.some(substring => source.includes(substring)));
或使用
lodash
包括
过滤器
):


这里有一个单行程序来实现这一点(使用ES6 arrow函数,因此如果不进行传输,可能需要将其重写为正则
function(){}
)。您根本不需要
lodash

var a = ["General election 2017: No cut to UK aid spending, says May", "Paris Champs Elysees attack gunman named as Karim Cheurfi", "William and Kate surprise Radio 1 visit", "South Africa bus crash 'kills at least 19 children'", "Len McCluskey re-elected as Unite general secretary", "Cleethorpes car crash captured on CCTV", "Adam Johnson prison video investigated", "Julian Assange's arrest a 'priority' for US attorney general", "Shrewsbury trust warned over baby heart monitoring in 2007", "High heels row: Petition for work dress code law rejected"];
var b = ["South Africa", "United States"];
var match = a.filter(source => b.some(substring => source.includes(substring)));
或使用
lodash
包括
过滤器
):

使用: 除了接受比较器外,此方法类似于
\uu.intersection
调用它来比较数组的元素。秩序和 结果值的引用由第一个数组确定。这个 使用两个参数调用比较器:
(arrVal,othVal)

\与(新闻,文字,(文章,文字)=>文章。包括(文字))


使用:
使用常用Javascript: 使用: 除了接受比较器外,此方法类似于
\uu.intersection
调用它来比较数组的元素。秩序和 结果值的引用由第一个数组确定。这个 使用两个参数调用比较器:
(arrVal,othVal)

\与(新闻,文字,(文章,文字)=>文章。包括(文字))


使用:
使用常用Javascript: 它会帮助你的。迭代新闻数组并通过迭代国家数组查找国家名称索引


它会帮助你的。迭代新闻数组并通过迭代国家数组查找国家名称索引。

您也可以使用lodash进行此操作。
\uCrossion
将比较精确值,因此不起作用。您也可以使用lodash进行此操作。
\uCrossion
将比较精确值,因此不起作用。
news.filter(article => words.some(word => article.includes(word)));
news.filter(function(article){
    return words.some(function(word){
       return article.indexOf(word) > -1;
  });
});
Array.indexOf()