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 wordsToRe
forEach
on fullWordList
is not required, use filter
on fullWordList
and indexOf()
in your function in filter()
to check if a number exists in wordsToRemove
or not.
var fullWordList = ['1','2','3','4','5'];
var wordsToRemove = ['1','2','3'];
var newList = fullWordList.filter(function(x){
return wordsToRemove.indexOf(x) < 0;
})
console.log(newList);