Intro to Sets


Sets is a data structure that was introduced to Javascript in 2015(ES6). A set is very similar to an array , but it only allows unique values. However, like arrays it can store any primitive and any iterable object while keeping the order of insertion.

Set has functions that are pretty easy to understand. Let’s hop into some code

Pratical Scenario

Let’s say we have a room where we invited 5 random varsity players for an interview. For each player we represent them as an emoji. However we want to a second data structure that shows the unique teams in the room. We made this unique set in the first example, but we can make it in a short syntax from the first array.

Initialize a Set with Any Iterable

Any iterable can be used to initialize a set, so Maps, Arrays, Strings, and others Sets are fair game

Take Your Javascript Skills to The Next Level

Here at CodingPhase we offer a comprehensive Future-Proof Javascript and ESNEXT – ES6, ES7, ES8 which will cover all the modern Javascript. Hiring managers are looking for people who are up to date with the latest language specifications

Sign up for a monthly subscription for $20/m and also get access to our  Object Oriented Programming with Javascript  and our Learn React by Building a Craigslist Clone