Personally I’d have this return a map instead of an object, so that the keys aren’t forced to be strings. Otherwise seems like a reasonable API, very similar to groupBy in any other moderately functional language, except with the “keys must be strings” restriction inherited from returning a plain object.<p>Also, for those thinking JS objects can have non-string keys, they can’t, it just sometimes appears that way due to JS type coercion: <a href="https://www.becomebetterprogrammer.com/can-javasscript-object-keys-be-numbers-or-non-string-values/" rel="nofollow">https://www.becomebetterprogrammer.com/can-javasscript-objec...</a><p>Edit: as pointed out by shawnz, this isn’t entirely accurate, JS object keys can also be symbols.