O'Reilly logo

Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond by JD Isaacks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Lesson 24. Sets

After reading lesson 24, you will

  • Know how to use and create sets
  • Know how to perform array operations on sets
  • Understand when to use arrays and when to use sets
  • Understand what WeakSets are and when to use them

Sets are a new type of object in JavaScript. A set is a unique collection of data. It can store any data type but won’t store duplicate references to the same value. Sets are iterables, so you can use spread and for..of with them. Sets are most closely related to arrays; however, when you use an array your focus is generally on the individual items in the array. When dealing with a set, you’re usually dealing with the set as a whole.

Consider this

Imagine you’re building a video game where the player starts ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required