const arr = [
[0, 1, 2, 3, 5],
[5, 1, 9, 7],
[3, 9, 0, 4, 1, 5],
[7, 8, 1, 6, 5]
];
var newArr = arr.reduce(function (prev, cur) {
prev = prev.filter(v => cur.includes(v)) //交集
// prev = prev.concat(cur.filter(v => !prev.includes(v))) // 并集
console.log('prev', prev);
return prev;
});
console.log(newArr);
JS_js二维数组求交集和并集
最新推荐文章于 2022-09-23 17:19:14 发布