这是以前写的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const data = [{
        id1,
        title"与想隆鼻客户打心理战"
    },
    {
        id2,
        title"与想隆鼻客户打心理战"
    },
    {
        id3,
        title"hhhhh"
    }
]


 let result = {};
 let finalResult=[];
 for(let i=0;i<data.length;i++){
     result[data[i].title]=data[i];
 }
 for(item in result){
     finalResult.push(result[item]);
 }

console.log('原始数据:', data, finalResult)

今天看了都不知道这是什么鬼,所以使用(ES6)优化下

这是现在优化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const data = [{
        id1,
        title"与想隆鼻客户打心理战"
    },
    {
        id2,
        title"与想隆鼻客户打心理战"
    },
    {
        id3,
        title"hhhhh"
    }
]

const finalResult = data.reduce((acc, cur) => {
!acc.map(i => i.title).includes(cur.title) && acc.push(cur)
return acc
},[])
console.log(finalResult)