js 多个数组取其相同的元素即子集

描述:有多个数组,取出其中重复的元素,也就是取子集

let a = [1,2,3,5,9,9,9,2,2,8,10,10];

let b = [10,11,2,3,4,5,9,9,9,2,8,10];
let c = [2,5,6,3,4,0,8,2,9,9,9,8,8,9,8,9,8,10];
let d = [a,b,c];

let e = [];
d.map((val1) => {
if (e.length == 0) {
e = val1;
} else {
e = e.filter((val2) => {
return val1.includes(val2);
})
}
})
console.log(e);// (11) [2, 3, 5, 9, 9, 9, 2, 2, 8, 10, 10]
console.log(new Set(e));// Set(6) {2, 3, 5, 9, 8, 10}
console.log(Array.from(new Set(e)));// (6) [2, 3, 5, 9, 8, 10]







posted @ 2020-04-29 12:01  张瑞奇  阅读(397)  评论(0编辑  收藏