-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets.js
More file actions
38 lines (28 loc) · 801 Bytes
/
sets.js
File metadata and controls
38 lines (28 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Sets in JS
// Defining the set
let mySet = new Set();
console.log(mySet);
// Adding some values to the set
mySet.add("Hello");
mySet.add("World");
console.log(mySet);
// Knowing the size of set
console.log(mySet.size);
// Adding Hello one more time to the set but it will not show up because sets only show unique values
mySet.add("Hello");
console.log(mySet);
// Deleting Hello from the set
mySet.delete("Hello");
console.log(mySet);
// Checking if set has Hello or not
let res = mySet.has("Hello");
console.log(res);
// Printing the keys of set
console.log(mySet.keys());
// Printing the values of set
console.log(mySet.values());
// Printing the entries of set
console.log(mySet.entries());
// Clearing the set
mySet.clear();
console.log(mySet);