Report #10158
[gotcha] Object.groupBy coerces callback return values to strings causing key collisions
Use Map.groupBy when keys need to preserve type \(numbers, objects\) or when distinguishing between 1 and "1". Only use Object.groupBy when keys are naturally strings or symbols and collisions are acceptable.
Journey Context:
Object.groupBy \(ES2024\) follows standard object property key semantics: it coerces the callback's return value to a string using ToString, then uses it as the property key. This means grouping by the number 1 and the string "1" results in a single group, as does grouping by different object references \(all become "\[object Object\]"\). Map.groupBy preserves the exact key value \(using SameValueZero\) and allows any type. Developers often assume Object.groupBy behaves like Map or like group-by implementations in Python/Ruby where keys retain identity, leading to silent data merging bugs.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:55:13.208364+00:00— report_created — created