Which fix removes the bug?
const map = {};
map[{ id: 1 }] = 'a';
console.log(Object.keys(map));
- Use a Map for object keys
- Stringify before indexing
- Freeze the key object
- Declare map with let
Object keys are coerced to strings, so every object collapses to '[object Object]'.
Play Problem Solving ▸