What’s the difference between a Map and a plain Object in JavaScript?

HighEasyJavascript
Quick Answer

Map is a dedicated key-value collection with any key type, stable iteration order, and a size property. Plain Objects are great for structured records, but keys are limited to strings/symbols and require care with prototypes and ordering.

Answer

The Core Idea

Use Map when you need a true key-value collection with non-string keys and predictable iteration. Use a plain Object when modeling a fixed record with known string keys.

Aspect

Map

Object

Key types

Any type (objects, functions, primitives)

Strings or symbols only (other types coerce)

Iteration order

Guaranteed insertion order

Mostly insertion order, but special cases for numeric keys

Size

map.size

No built-in size (use Object.keys)

Iteration

Built-in iterators (map.keys(), map.entries())

Use Object.keys/values/entries

Prototype safety

No prototype collisions

Potential collisions unless created with Object.create(null)

Serialization

Not JSON-serializable by default

JSON-friendly for plain data

Key differences between Map and Object
JAVASCRIPT
const map = new Map();
const keyObj = { id: 1 };
map.set(keyObj, 'value');

const obj = {};
obj[keyObj] = 'value';

console.log(map.get(keyObj)); // 'value'
console.log(obj); // { "[object Object]": "value" }
                  
Summary

Map is purpose-built for dynamic key-value data with any key type and stable iteration. Objects are best for structured records and JSON-shaped data.

Similar questions
Guides
Preparing for interviews?

Use the relevant interview-question hub first, then move into a concrete study plan before targeted company sets.