数组中的对象去重
let arr = [{ from: '张三', to: '河南', }, { from: '王二', to: '阿里', }, { from: '王二', to: '杭州', }, { from: '王二', to: '山东', }, ]; unique(arr) { const res = new Map(); return arr.filter( (item: { from: any }) = > !res.has(item.from) && res.set(item.from, 1)); } unique(arr) { return arr.reduce( (all: any, next: any) = > all.some((atom: any) = > atom.value === next.value) ? all : [...all, next], []); }
参考链接:https://www.cnblogs.com/lilelile/p/11350962.html
参考链接:https://blog.csdn.net/wang1006008051/article/details/86551275