Using .filter to compare two arrays and return values that aren't matched

后端 未结 5 1269
Happy的楠姐
Happy的楠姐 2021-02-03 14:46

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

5条回答
  •  春和景丽
    2021-02-03 15:29

    Perhaps you could try

    var fullWordList = ['1','2','3','4','5'];
    var wordsToRemove = ['1','2','3'];
    var match = [];
    
    for(let word of fullWordList){
        if(!wordsToRemove.find((val) => val == word))match.push(word);
    }
    

提交回复
热议问题