🌐 AI搜索 & 代理 主页
Skip to content

Commit fa9ca84

Browse files
authored
Maps in JS
1 parent 6a4c4e0 commit fa9ca84

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

maps.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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());

0 commit comments

Comments
 (0)