第一种情况
const deps = {
'采购部':[1,2,3],
'人事部':[5,8,12],
'行政部':[5,14,79],
'运输部':[3,64,105],
}
let member = [...new Set(Object.values(deps).flat(Infinity))]
console.log(member)
第二种情况
//扁平化加上去重
const arr = [1, [2, 3], [[3, 4, 2], 1], 5, [3]]
const flatten = (arr) => {
return arr.reduce((pre, next) => {
return [...new Set(pre.concat(Array.isArray(next) ? flatten(next) : next))]
}, [])
}
console.log(flatten(arr))