普通数组去重
方法1
let schoolIdsList = ["x001","x002","x003","x001","x002","x001"];
let newSchoolIdsList = [...new Set(schoolIdsList )];
console.log(newSchoolIdsList ); // [ 'x001', 'x002', 'x003']
方法2
let arr = [1, 2, 3, 2, 1];
function unique(arr){
return Array.from(new Set(arr));
}
console.log(unique(arr)) // [1, 2, 3]
对象数组去重
let qu = res.list.map(item=>({
areaId:item.areaId,
areaName:item.areaName,
cho:false
}))
let areaId = 'areaId';
let qu1 = qu.reduce((all, next) => all.some((atom) => atom[areaId] == next[areaId]) ? all : [...all, next],[]);
网友评论