📜  js 删除 json 重复值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:45.849000             🧑  作者: Mango

代码示例1
var data = [{
    "name": "Peter",
    "age": 30,
    "hair color": "brown"
}, {
    "name": "Steve",
    "age": 55,
    "hair color": "blonde"
}, {
    "name": "Steve",
    "age": 55,
    "hair color": "blonde"
}]

 data = this.data.filter((obj, pos, arr) => {
   return arr
     .map(mapObj => mapObj.name)
     .indexOf(obj.name) == pos;
 });

console.log(data);
/*
[{
    "name": "Peter",
    "age": 30,
    "hair color": "brown"
}, {
    "name": "Steve",
    "age": 55,
    "hair color": "blonde"
}]
*/