Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

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)

Set Data Structure

Kostas Diakogiannis
Module by Kostas Diakogiannis, updated more than 1 year ago
No tags specified