arrPush() {
this.infoList = [
{ name: "小明" },
{ name: "小明" },
{ name: "小明" },
{ name: "小孙" },
{ name: "小周" },
{ name: "小陈" }
];
//这是你接口返回的数据
//定义一个空对象是你要往数组中push的
// this.manList = this.infoList.reduce((cur, next) => {
// obj[next.name] ? "" : (obj[next.name] = true && cur.push(next));
// return cur;
// }, []); //设置cur默认类型为数组,并且初始值为空的数组
const obj = {};
this.manList = this.infoList.filter((item) =>
obj[item.name] ? "" : (obj[item.name] = true)
);
console.log(this.manList);
}
帮小白同事写的一个方法