Created
September 18, 2019 19:10
-
-
Save mikemcbride/063583d4b08f526fa3995c0260c61f65 to your computer and use it in GitHub Desktop.
Like uniqBy from lodash without needing all of lodash
This file contains 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
// unique array of objects by specific key | |
const uniqBy = function (arr, key) { | |
let seen = new Set() | |
return arr.filter(it => { | |
let val = it[key] | |
if (seen.has(val)) { | |
return false | |
} else { | |
seen.add(val) | |
return true | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment