-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap-weekmap.js
More file actions
61 lines (46 loc) · 1.02 KB
/
Copy pathmap-weekmap.js
File metadata and controls
61 lines (46 loc) · 1.02 KB
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
51
52
53
54
55
56
57
58
59
60
61
// Map
const someObject = {
prop1: "Property One",
prop2: 1
}
const entries = [
["prop1", "Property Two"],
["prop2", 2]
]
console.log(Object.entries(someObject));
console.log(Object.fromEntries(entries));
const map = new Map(entries);
console.log(map);
console.log(map.get("prop2")); // console.log(someObject.prop2);
map.set("newProp", 3)
.set(NaN, "Not a Number");
console.log(map.get(NaN));
console.log(map.has(NaN));
console.log(map.size);
// map.clear();
// console.log(map.size);
for (const [key, value] of map) {
console.log(key, value);
}
for (const val of map.values()) {
console.log(val);
}
for (const key of map.keys()) {
console.log(key);
}
map.forEach((val, key, item) => {
console.log(val, key);
});
// WeakMap
let weekObject = {
prop1: "Property One",
prop2: 1
}
// const array = [weekObject];
// weekObject = null;
// console.log(weekObject);
const weekMap = new WeakMap([
[weekObject, "Week object"]
]);
weekObject = null;
console.log(weekMap.get(weekObject));