-
Notifications
You must be signed in to change notification settings - Fork 2
/
maps.js
50 lines (37 loc) · 962 Bytes
/
maps.js
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
39
40
41
42
43
44
45
46
47
48
49
50
// we can actually access any element's key using string value
const fruits = new Map([
["apples", 500],
["bananas", 300],
["oranges", 200]
]);
fruits.forEach(element => {
console.log(element);
});
// .set() can be used to add new elements and update value of existing element
const arr = new Map();
arr.set("yo",3);
arr.set("hey you",31);
arr.set("there",6);
arr.set("hq",42);
arr.set("dwsx",7);
arr.set("downtown",91);
console.log("array before update");
arr.forEach(element1 => {
console.log(element1);
});
// update element :
arr.set("hq",88);
console.log("array after update");
arr.forEach(element1 => {
console.log(element1);
});
// delete element
arr.delete("yo");
console.log("array after delete");
arr.forEach(element1 => {
console.log(element1);
});
// array size
console.log("array size "+arr.size);
//The has() method returns true if a key exists in a Map:
console.log("array has "+arr.has("downtown"));