(1)去除id相同的对象
let person = [
{ id:1 , text: 3},
{ id:2 , text: 4},
{ id:5 , text: 3},
{ id:1 , text: 2}
];
let obj = {};
person = person.reduce( ( pre,cur ) => {
obj[cur.id] ? "" : obj[cur.id] = true && pre.push(cur);
return pre;
},[]);
console.log(person);
得出结果:
person = [
{id: 1, text: 3}
{id: 2, text: 4}
{id: 5, text: 3}
]