思路:利用数组原型对象上的 forEach 和 includes 方法
arr:需要去重的数组;t:根据 指定字段进行去重
getDisArray(arr, t = "") {
const newArr = [], assignList = []
// 有指定字段
if (t) {
arr.forEach(item => {
if (!assignList.includes(item[t])) {
assignList.push(item[t])
newArr.push(item)
}
})
}
// 无指定字段
else {
arr.forEach(item => {
return newArr.includes(item) ? "" : newArr.push(item)
})
}
return newArr
}