Last active
September 6, 2017 10:33
-
-
Save BukhariH/f3a9e4988b8809e981eb2f6b9336eb66 to your computer and use it in GitHub Desktop.
Get unique properties from JSON object
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
// Turn const ARRAY = [{type: "FOO", content: "Test 0"}, {type: "BAR", content: "Test 1"}, {type: "FOO", content: "Test 2"}] | |
// Into ["FOO", "BAR"] | |
// Using getUniqueProperties(ARRAY, 'type') | |
getUniqueProperties = (array, property)=>{ | |
return [...new Set(array.map(elem => elem[property]))] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment