unique(arr, type) {
if (arr.length === 0) {
return arr;
} else {
if (type) {
const obj = {};
const newArr = arr.reduce((cur, next) => {
obj[next[type]] ? '' : obj[next[type]] = true && cur.push(next);
return cur;
}, []);
return newArr;
} else {
return Array.from(new Set(arr));
}
}
}
网友评论