File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Sets in JS
2
+
3
+ // Defining the set
4
+ let mySet = new Set ( ) ;
5
+ console . log ( mySet ) ;
6
+
7
+ // Adding some values to the set
8
+ mySet . add ( "Hello" ) ;
9
+ mySet . add ( "World" ) ;
10
+ console . log ( mySet ) ;
11
+
12
+ // Knowing the size of set
13
+ console . log ( mySet . size ) ;
14
+
15
+ // Adding Hello one more time to the set but it will not show up because sets only show unique values
16
+ mySet . add ( "Hello" ) ;
17
+ console . log ( mySet ) ;
18
+
19
+ // Deleting Hello from the set
20
+ mySet . delete ( "Hello" ) ;
21
+ console . log ( mySet ) ;
22
+
23
+ // Checking if set has Hello or not
24
+ let res = mySet . has ( "Hello" ) ;
25
+ console . log ( res ) ;
26
+
27
+ // Printing the keys of set
28
+ console . log ( mySet . keys ( ) ) ;
29
+
30
+ // Printing the values of set
31
+ console . log ( mySet . values ( ) ) ;
32
+
33
+ // Printing the entries of set
34
+ console . log ( mySet . entries ( ) ) ;
35
+
36
+ // Clearing the set
37
+ mySet . clear ( ) ;
38
+ console . log ( mySet ) ;
You can’t perform that action at this time.
0 commit comments