我在比较两个数组的元素并过滤掉匹配值时遇到了一些问题.我只想返回未包含在其中的数组元素wordsToRemove.
var fullWordList = ['1','2','3','4','5'];
var wordsToRemove = ['1','2','3'];
var filteredKeywords = fullWordList.forEach(function(fullWordListValue) {
wordsToRemove.filter(function(wordsToRemoveValue) {
return fullWordListValue !== wordsToRemoveValue
})
});
console.log(filteredKeywords);
Run Code Online (Sandbox Code Playgroud)
Alb*_*res 11
var fullWordList = ['1','2','3','4','5'];
var wordsToRemove = ['1','2','3'];
var filteredKeywords = fullWordList.filter((word) => !wordsToRemove.includes(word));
console.log(filteredKeywords);Run Code Online (Sandbox Code Playgroud)