Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  12] [ 3]  / answers: 1 / hits: 54474  / 7 Years ago, wed, august 9, 2017, 12:00:00

I'm having some issues comparing the elements of two arrays and filtering out matching values. I only want to return array elements that are NOT included within 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);

More From » javascript

 Answers
14

You can use filter and includes to achieve this:





var fullWordList = ['1','2','3','4','5'];
var wordsToRemove = ['1','2','3'];

var filteredKeywords = fullWordList.filter((word) => !wordsToRemove.includes(word));

console.log(filteredKeywords);




[#56812] Monday, August 7, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sidneyh

Total Points: 118
Total Questions: 108
Total Answers: 105

Location: Mali
Member since Fri, Jun 18, 2021
3 Years ago
sidneyh questions
Tue, Jun 7, 22, 00:00, 2 Years ago
Wed, Apr 13, 22, 00:00, 2 Years ago
Wed, Aug 12, 20, 00:00, 4 Years ago
Wed, Jun 3, 20, 00:00, 4 Years ago
Fri, Apr 24, 20, 00:00, 4 Years ago
;