J.D.B. DIASOLUKA Nz. Luyalu
JavaScript Tome-XXII
Maps && WeakMaps
- 5/27 - mardi, 26. mars 2019 (1:59 )
['a', 56], [Date.now(), 40],
[78, 'c'], [41, Date.now()]
]);
console.log(map);
// Map(4) { a -> 56, 1544277041459 -> 40,
// 78 -> "c", 41 -> 1544277041459 }
let kya=[], vla=[];
for (var [cle, valeur] of map) {
kya=kya.concat(cle);
vla.push(valeur);
}
console.log(kya);
// Array(4) [ "a", 1544277173449, 78, 41 ]
console.log(vla);
// Array(4) [ 56, 40, "c", 1544277173449 ]
let vl = [];
for (let valeurs of map.values()){
vl=vl.concat(valeurs);
}
console.log(vl);
// Array(4) [ 56, 40, "c", 1544277643496 ]
let ky = [];
for (var cles of map.keys()){
ky.push(cles);
}
console.log(ky);
// => Array(4) [ "a", 1544277741029, 78, 41 ]
</script>
Lisez les commentaires dans le code ci-dessous :
<script type="text/javascript"> "use strict";
var a = [Date.now()];
console.log(a); // Array [ 1544273035052 ]
var map = new Map([['a', 20], [18, 35], [91, 54]]);
console.log(map);
// Firefox : Map { a -> 20, 18 -> 35, 91 -> 54 }
// Yandex : Map(2) {"a" => 20, 18, 91 -> 54 => 35}