Skip to content

Instantly share code, notes, and snippets.

@daehli
Created January 11, 2018 02:48
Show Gist options
  • Save daehli/363fb4736a34df8e72756c23d58c7f4a to your computer and use it in GitHub Desktop.
Save daehli/363fb4736a34df8e72756c23d58c7f4a to your computer and use it in GitHub Desktop.
Set In Javascript

What's a Set in Javascript

A Set is a Collection of values. You can iterate over your Set and your Set can only have single values

const setOfColors = new Set(['Blue','Red','Orange'])
// setOfColors[0] = Blue
// setOfColors[1] = Red
// setOfColors[2] = Orange

Now you can Iterage over Your set Of Colors

const myFavoriteColors = ['Blue','Pink','Green']

const myFavoriteColorIsPresentInSet = myFavoriteColors.filter(x=>setOfColors.has(x))
// console.log(myFavoriteColorIsPresentInSet) => Blue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment