TRADEOFF BATTLE

Object vs Map for keyed JavaScript collections

A dashboard keeps adding, removing, counting, and iterating items by id. Would you store that data in a plain object or a Map?

javascripteasy11 min

The prompt

You are building a JavaScript dashboard that tracks selected rows by id. The UI needs to add and remove entries often, check whether an id already exists, show a count badge, iterate through the current selections, and clear the whole collection quickly. The ids are string values today, but the set behaves like a living collection rather than a fixed record shape. In the interview, the panel asks whether you would store this in a plain object or a Map.

Which direction would you defend for this prompt, and how would you explain when the other option is still the better answer?

Pick the direction you would defend

You are not looking for the universal winner. You are picking the strongest answer for this prompt.

Commit to a direction

Pick the option you would defend, then reveal the stronger interview framing for this prompt.

Next step

Choose one side first

This works better when you commit to an answer before seeing the breakdown.

Strong answers are scenario-specific, not universal.