What Are the Advantages of Using a Map over an Object?
Problem
When is it better to use a map rather than an object?
Solution
While there are similarities to maps and objects, maps can contain both objects and primitives as keys or values.
The Code
Listing 11-1. Maps Can Use Different Types as Keys, Whereas Objects Use Strings
var mapObj = new Map();
mapObj.set('myString', 'myString is a string key');
console.log(mapObj.get('myString')); //myString is a string key
var myObj = {};
mapObj.set(myObj, 'Object is a used as a key');
console.log(mapObj.get(myObj)); ...