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/a01ec63f13da3b6fa4a5603eb9484bf7 to your computer and use it in GitHub Desktop.
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
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