Sets are still relatively new in JavaScript and I still don’t see people taking full advantage of them.

In this article, we will explore the features of Sets and also look into a few examples where Sets can make our life easier.

General Concepts

A Set is a collection of elements that maintain insertion order, and only allows unique elements. If you insert five1’s in a row, only one will be inserted. When inserting, it will compare elements using === to determine if they should be inserted.

We need to be conscious of this fact because objects which are the exact same but have different references will in fact be inserted since they are being compared by reference.

Adding Values To A Set

How can we create a set? The simplest way is by using the Set constructor.

const mySet  = new Set();

#programming #javascript-development #javascript #coding

Introduction to Sets in JavaScript
1.30 GEEK