1const addresses = [...]; // Some array I got from async call
2
3const uniqueAddresses = Array.from(new Set(addresses.map(a => a.id)))
4 .map(id => {
5 return addresses.find(a => a.id === id)
6 })
1let person = [
2{name: "john"},
3{name: "jane"},
4{name: "imelda"},
5{name: "john"},
6{name: "jane"}
7];
8
9const data = Array.from(new Set(person.map(JSON.stringify))).map(JSON.parse);
10console.log(data);
1let person = [
2{name: "john"},
3{name: "jane"},
4{name: "imelda"},
5{name: "john"},
6{name: "jane"}
7];
8
9const obj = [...new Map(person.map(item => [JSON.stringify(item), item])).values()];
10console.log(obj);
1arr.reduce((acc, current) => {
2 const x = acc.find(item => item.id === current.id);
3 if (!x) {
4 return acc.concat([current]);
5 } else {
6 return acc;
7 }
8}, []);
1function remove_duplicate_objects(data,prop) {
2 var seen = {};
3 data = data.filter(function (entry) {
4 if (seen.hasOwnProperty(entry[prop])) {
5 return false;
6 }
7
8 seen[entry.prop] = entry;
9 return true;
10 });
11 return data
12 }
13
14const new_array = remove_duplicate_objects([array with objects inside])