我有一个字符串“这个字符串中有多个单词”,我有一个数组有多个单词[“There”,“string”,“multiple”]。我想匹配我的字符串与这个数组,它应该返回true,如果数组中的所有单词都存在于字符串中。如果数组中的任何一个单词不存在于字符串中,它应该返回false。Javascript选择字符串,如果它匹配数组中的多个单词
var str = "There are multiple words in this string";
var arr = ["There", "string", "multiple"]
这应该返回true。
var str = "There are multiple words in this string";
var arr = ["There", "hello", "multiple"]
由于“hello”不存在于字符串中,因此应该返回false。
这是如何在纯JavaScript中高效完成的?
打动你的老师:'arr.every(Set.prototype.has.bind(新集( str.split(''))))' – georg