两组数组对象,合并后去重
代码
// value值相同的去掉
let newarr = [];
let arr1 = [{ value: 1, label: 'a1' }, { value: 2, label: 'a2' }, { value: 3, label: 'a3' }]
let arr2 = [{ value: 1, label: 'a1' }]
newarr = [...arr2, ...arr1];
let result = []
let hash = {}
result = newarr.reduce((item, next) => {
hash[next.value] ? '' : hash[next.value] = true && item.push(next)
return item
}, [])