-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
83 lines (61 loc) · 1.92 KB
/
map.js
File metadata and controls
83 lines (61 loc) · 1.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// const contacts = new Map();
// contacts.set('Jessie', { phone: '555-111-1111', address: '111 Main St.' });
// contacts.has('Jessie'); // true
// contacts.get('Hillary'); // undefined
// console.log(contacts.get('Lekan'));
// console.log(contacts.size);
// console.log(contacts.values('Jessie'));
// console.log(contacts.entries('Jessie'));
// //how can I use this? get Map[@@species]
// const myMap = new Map();
// const keyString = 'a String';
// const keyObj = {};
// const keyFunc = function () {};
// myMap.set(keyString, 'value associated with string');
// myMap.set(keyObj, 'value associated with keyObj');
// myMap.set(keyFunc, 'value associated with keyFunc');
// console.log(myMap.get(function () {}));
// myMap.set(NaN, 'not a number');
// console.log(myMap.get(NaN));
// const otherNaN = Number('foo');
// myMap.set(otherNaN, 'also not a number');
// console.log(myMap.get(otherNaN));
// const myMap = new Map();
// myMap.set(0, 'zero');
// myMap.set(1, 'one');
// // for (const [key, value] of myMap) {
// // console.log(`${key} = ${value}`);
// // }
// for (const [key, value] of myMap.entries()) {
// console.log(`${key} = ${value}`);
// }
// myMap.forEach((value, key) => {
// console.log(`${key} = ${value}`);
// });
// const kvArray = [
// ['key1', 'value'],
// ['key2', 'value2'],
// ];
// const myMap = new Map(kvArray);
// console.log(myMap);
// // console.log(Array.from(myMap));
// console.log([...myMap]);
// console.log(Array.from(myMap.keys()));
const original = new Map();
original.set(1, 'one');
console.log(original);
// passing a map to a map create a copy of the original map and not a reference to the original map
const copy = new Map(original);
console.log(copy === original); // false
// console.log(copy === original);
const first = new Map([
[1, 'one'],
[2, 'two'],
[3, 'three'],
]);
const second = new Map([
[1, 'uno'],
[2, 'dos'],
[3, 'tres'],
]);
console.log([...first, ...second]);