.filter() array using another array's elements

前端 未结 5 1674
陌清茗
陌清茗 2020-12-09 13:02

I have an array of people\'s names along with their knowledge of languages. What I want to do is pass a filter onto the language column and filter out any results that don\'

5条回答
  •  执笔经年
    2020-12-09 13:38

    this is the ultimate solution in the ES6 way: No need to Search the same query again in another thread.

    var array1 = ['a', 'b', 'c', 'd', 'e'];
    var array2 = ['b', 'd', 'f'];
    
    array1 = array1.filter(function(item) {
      return !array2.includes(item); 
    })
    console.log(array1); // [ 'a', 'c', 'e' ]
    console.log(array2); // [ 'b', 'd', 'f' ]

提交回复
热议问题