remove duplicated from array of object code example
Example 1: how to remove duplicate array object in javascript
let person = [
{name: "john"},
{name: "jane"},
{name: "imelda"},
{name: "john"},
{name: "jane"}
];
const data = Array.from(new Set(person.map(JSON.stringify))).map(JSON.parse);
console.log(data);
Example 2: remove duplicate objects from array javascript
const addresses = [...];
const uniqueAddresses = Array.from(new Set(addresses.map(a => a.id)))
.map(id => {
return addresses.find(a => a.id === id)
})
Example 3: how to remove duplicate array object in javascript
let person = [
{name: "john"},
{name: "jane"},
{name: "imelda"},
{name: "john"},
{name: "jane"}
];
const obj = [...new Map(person.map(item => [JSON.stringify(item), item])).values()];
console.log(obj);
Example 4: js remove json value duplicates
var json = [
{"text":"menu1","parent":"#","id":"128102"},
{"text":"menu1.1","parent":"128102","id":"128103"},
{"text":"menu1.1","parent":"128102","id":"128103"}
];
var ids = [];
var clean = [];
$.each(json, function(index, value) {
if($.inArray(value.id, ids) == -1)
{
ids.push(value.id);
clean.push(value);
}
});