Created
November 3, 2020 19:49
-
-
Save DoctorDerek/a01ec63f13da3b6fa4a5603eb9484bf7 to your computer and use it in GitHub Desktop.
How to Use Set with an Array of Objects to Find The Unique Values Among Those Objects
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
const yearsArray = [{ year: 1999 }, { year: 2000 }, { year: 1999 }] | |
const arrayOfOnlyYears = yearsArray.map((object) => object.year) | |
const uniqueYears = [...new Set(arrayOfOnlyYears)] | |
console.log(uniqueYears) // [1999,2000] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment