According to MDN, the size
property of a Map
object should represent the number of entries the Map
object has. However, if I create an empty Map
and use the bracket notation (not sure what the formal name for this is) to add a key/value pair, the size
property is not updated. However, if I use the Map.set(key, value)
function, then the property is updated. Why is this?
Example:
var ex = new Map();
ex['key1'] = 'value1';
ex.set('key2', 'value2');
After running this, ex.size
returns 1
.