//只能处理简单数组 比如[1,2,1,2] ['阿','啊','阿毛子','阿']
export function filterArr(arr) {
if (!Array.isArray(arr)) {
console.log('type error!')
return
}
return [...new Set(arr)]
}
//ts语法可以处理数组里面为对象形式比如 [{a:'2'},{a:'1'}{a:'1'}]
// 去重过滤数组对象 指定字段唯一值 数组,对象指定key名称
export const filterKeyField = (arr: [], val: string) => {
const res = new Map()
return arr.filter((item) => !res.has(item[val]) && res.set(item[val], 1))
}