HomeToolsAbout a20k

Map

What is it

Object that holds key-value pairs and remembers the original insertion order of the keys

Map can only have one unique key

const map1 = new Map(); map1.set('a', 1); map1.set('b', 2); map1.set('c', 3); console.log(map1.get('a')); // 1 map1.set('a', 97); console.log(map1.get('a')); // 97 console.log(map1.size); // 3 map1.delete('b'); console.log(map1.size); // 2

Cloning Map

const original = new Map([ [1, 'one'] ]); const clonedMap = new Map(original); console.log(clonedMap.get(1)); // one console.log(original === clonedMap); // false
© VincentVanKoh