Skip to content

Instantly share code, notes, and snippets.

@manjufy
Last active September 8, 2017 09:25
Show Gist options
  • Save manjufy/a624202a81928651d24ed17d186cb3a2 to your computer and use it in GitHub Desktop.
Save manjufy/a624202a81928651d24ed17d186cb3a2 to your computer and use it in GitHub Desktop.
Find unique objects from an array
'use strict';
const data = [{
name: "Schumacher",
races: 97
}, {
name: "Vettel",
age: 45
}, {
name: "Hamilton",
age: 58
}, {
name: "Schumacher",
age: 65
}];
let result = data
.filter((value, index, self) => {
const final = self.findIndex( t => t.name === value.name)
return final === index
})
console.log(result);
// [ { "name": "Schumacher", "races": 97 }, { "name": "Vettel", "age": 45 }, { "name": "Hamilton", "age": 58 } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment