Last active
November 4, 2020 19:46
-
-
Save DoctorDerek/5585d61ca155dedd776dc7eaee9f714d to your computer and use it in GitHub Desktop.
How to find unique object values using Set in JavaScript ES6
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
// 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