File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ // Maps in JavaScript
2+
3+ // Creating a new MAP
4+ let myMap = new Map ( ) ;
5+
6+ // Defining keys
7+ const key1 = "myStr" ,
8+ key2 = { } ,
9+ key3 = function ( ) { } ;
10+ console . log ( myMap ) ;
11+
12+ // Setting the keys in the Map
13+ myMap . set ( key1 , "This is a string" ) ;
14+ myMap . set ( key2 , "This is an object" ) ;
15+ myMap . set ( key3 , "This is an empty function" ) ;
16+
17+ // Size of the Map
18+ console . log ( myMap . size ) ;
19+ console . log ( myMap ) ;
20+
21+ // Getting the values in the Map
22+ let value1 = myMap . get ( key1 ) ;
23+ let value2 = myMap . get ( key2 ) ;
24+ let value3 = myMap . get ( key3 ) ;
25+ console . log ( value1 , value2 , value3 ) ;
26+
27+ // Deleting key3 from Map
28+ myMap . delete ( key3 ) ;
29+ console . log ( myMap ) ;
30+
31+ // Checking if the Map has key3 or not
32+ let res = myMap . has ( key3 ) ;
33+ console . log ( res ) ;
34+
35+ // Printing the keys of map
36+ console . log ( "Keys in Map are :" , myMap . keys ( ) ) ;
37+
38+ // Printing the values of the map
39+ console . log ( "Values in Map are: " , myMap . values ( ) ) ;
40+
41+ // Printing the entries of the map
42+ console . log ( "Entries of the Map are: " , myMap . entries ( ) ) ;
You can’t perform that action at this time.
0 commit comments