Sets

Learn how to use sets, a data structure just introduced to JavaScript.

Introduction

Sets are a data structure commonly used in computer science.

A set is a collection of values. Think of it like a bucket. A set provides easy ways to insert and remove items. We can easily check if an item is present in our set and we can get all items back in a way that makes them easy to use.

Creating a Set

We invoke a set using:

new Set();

Inside the constructor call, we can pass in an iterable object, usually an array. Every item in the array will be inserted into the set.

Get hands-on with 1200+ tech skills courses.