Jump to content

JavaScript: Difference between revisions

557 bytes added ,  4 February 2020
Line 150: Line 150:


===Map===
===Map===
[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map Reference]
<syntaxhighlight lang="js">
let myMap = new Map();
let keyObj    = {};
// Set value
myMap.set(keyObj, 'value associated with keyObj');
// Get size
myMap.size;
// Get value
myMap.get(keyObj);
// Check if key is in the map
myMap.has(keyObj);
// Delete
myMap.delete(keyObj);
</syntaxhighlight>
;Notes
* You can mix and match types of keys
* The hash for objects are randomly generated under the hood
* Do not use <code>[]</code> to get or set from the map


===Set===
===Set===