GoConqr has a new look! Let us know what you think.

Module 9 of 10 · Media

Set Data Structure

Kostas Diakogiannis

Set Data Structure

The Set data structure

Set is an iterable JavaScript object that came through ECMA Script 6. It works like an array, the main difference is that it is primarily used for storing there unique values and it does NOT allow duplicates. 

The way to create a set is with the new Set() constructor. Inside the set you can pass an array as a seeding data, and all the data of the array is going to be used in order to be valid for data for a set (remove duplicates etc).

Some of the commonest methods when working with sets include: 

1. let mySet = new Set() // Creates a new empty set.

2. mySet.add('something') // Adds the value of something to mySet.

3. mySet.delete('something') // Deletes the value of 'something' from mySet.

4. mySet.has('something') // Returns a boolean if mySet contains a value of something

5. mySet.size // Returns a property of size (equivalent to length for arrays)

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?