1let person = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"}];
2
3function removeDuplicates(data, key) {
4
5 return [
6 ...new Map(data.map(item => [key(item), item])).values()
7 ]
8
9};
10
11console.log(removeDuplicates(person, item => item.name));
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}, []);
1arr.filter((v,i,a)=>a.findIndex(t=>(t.place === v.place && t.name===v.name))===i)
2