Skip to content

Object vs. Map

How Do You Compare Object and Map?

FeatureObjectMap
Key typesOnly strings and symbols are valid keys.Any value can be used as a key (objects, functions, primitives).
Key orderKeys are unordered (in practice, insertion order is mostly preserved for string keys, but not guaranteed).Keys are ordered by insertion; iteration follows insertion order.
Size propertyNo built-in way to get the number of keys; use Object.keys(obj).length.Use the .size property for the number of entries.
IterabilityNot directly iterable; use Object.keys, Object.values, or Object.entries.Directly iterable with for...of, .keys(), .values(), and .entries().
PrototypeHas a prototype chain; default properties can collide with custom keys (can be avoided with Object.create(null)).Does not have a prototype, so there are no default keys.
PerformanceMay be less efficient for frequent additions and removals.Optimized for frequent additions and deletions.
SerializationCan be easily serialized to JSON.Cannot be directly serialized to JSON.