Last active
September 8, 2017 09:25
-
-
Save manjufy/a624202a81928651d24ed17d186cb3a2 to your computer and use it in GitHub Desktop.
Find unique objects from an array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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