📜  比较和过滤两个数组 - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:40.139000             🧑  作者: Mango

代码示例1
var array1 = ['apples', 'grapes', 'oranges', 'banana'],
  array2 = ['potato', 'pears', 'grapes', 'berries', 'apples', 'oranges'];

var intersection = array1.filter(function(e) {
  return array2.indexOf(e) > -1;
});

console.log(intersection);