“Hapus Objek JSON Duplikat dari Array JavaScript” Kode Jawaban

JS Hapus nilai duplikat JSON

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"
}]
*/
Panicky Peafowl

Hapus Objek JSON Duplikat dari Array JavaScript

const temp =  [{first: 569, second: "789", third: "458"},  {first: 476, second : "147", third: "369"},  {first: 100, second: "200", third: "300"},  {first: 100, second: "200", third: "300"},   {first: 100, second: "200", third: "300"}];

const result = [...new Set(temp.map(obj => JSON.stringify(obj)))]
                 .map(str => JSON.parse(str));
console.log(result);
Lazy Locust

Jawaban yang mirip dengan “Hapus Objek JSON Duplikat dari Array JavaScript”

Pertanyaan yang mirip dengan “Hapus Objek JSON Duplikat dari Array JavaScript”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya