1const arr = [{id: 1, name: 'one'}, {id: 2, name: 'two'}, {id: 1, name: 'one'}]
2
3const ids = arr.map(o => o.id)
4const filtered = arr.filter(({id}, index) => !ids.includes(id, index + 1))
5
6console.log(filtered)
1//check one attribute
2let person = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"}];
3
4person = person.filter((item, index, self) =>
5 index === self.findIndex((t) => (
6 t.name === item.name
7 ))
8)
9
10//check two attributes
11let person = [{place: "uno", name: "john"}, {place: "duno", name: "jane"}, {place: "duno" ,name: "imelda"}, {place: "uno" ,name: "john"}];
12
13person = person.filter((item, index, self) =>
14 index === self.findIndex((t) => (
15 t.place === item.place && t.name === item.name
16 ))
17)
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 arr = [{name: "john"}, {name: "jane"}, {name: "imelda"}, {name: "john"}];
2
3const uniqueArray = arr.filter((v,i,a)=>a.findIndex(t=>(t.name===v.name))===i)
4console.log(uniqueArray);