Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • 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