JavaScript Map
You should use JavaScript Map when an object consists of ==key: value pairs and you frequently add and delete entries== (action performed).
Object to Map and vice versa
const eventMap = new Map();
// Object from Set
const obj = Object.fromEntries(eventsMap);
// Set from Object
const newMap = new Map(Oject.entries(obj));Advantages over JavaScript Objects
- Objects return
trueeven if they’re empty, which is wat behaviour.Maps are alwaysfalsewhen empty. - Maps will preserve order of keys
To array
const arr = [...myMap]