Skip to content

Instantly share code, notes, and snippets.

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 DoctorDerek/5585d61ca155dedd776dc7eaee9f714d to your computer and use it in GitHub Desktop.
Save DoctorDerek/5585d61ca155dedd776dc7eaee9f714d to your computer and use it in GitHub Desktop.
How to find unique object values using Set in JavaScript ES6
// You can use Object.values() with Set to find unique
// values in an object, but keys are always unique.
const myObject = { hello: "๐ŸŒ", hi: "๐ŸŒ", howdy: "๐Ÿšฏ" }
console.log(new Set(Object.keys(myObject)))
// Output: Set(3) [ "hello", "hi", "howdy" ]
console.log(new Set(Object.values(myObject)))
// Output: Set(2) [ "๐ŸŒ", "๐Ÿšฏ" ]
console.log(new Set(Object.entries(myObject)))
// Output: Set(3) [[ "hello", "๐ŸŒ" ], ...]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment