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

2021-02-03 16:21

阅读:613

标签:val   include   rom   子集   OLE   clu   from   个数   数组   

描述:

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]







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

标签:val   include   rom   子集   OLE   clu   from   个数   数组   

原文地址:https://www.cnblogs.com/zhangruiqi/p/12801272.html


评论


亲,登录后才可以留言!