Skip to content

Instantly share code, notes, and snippets.

@BukhariH
Last active September 6, 2017 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BukhariH/f3a9e4988b8809e981eb2f6b9336eb66 to your computer and use it in GitHub Desktop.
Save BukhariH/f3a9e4988b8809e981eb2f6b9336eb66 to your computer and use it in GitHub Desktop.
Get unique properties from JSON object
// 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