Object.groupBy(items, callback) walks an iterable (usually an array) and builds a plain object. For each item, callback returns a key (string or symbol). Matching items are collected into arrays under that key.
This method is relatively new (ES2024). Before using it in production, check typeof Object.groupBy === "function" or provide a fallback.
Syntax
Call Object.groupBy() like this. Start with this line.
JavaScript
Object.groupBy(items, callback)
Call
What it does
Object.groupBy(items, callback)
Groups items into an object of arrays keyed by each callback result.
Built into JavaScript (ES2024). Call on Object — no import required. Relatively new — verify support.
Second argument The callback signature is (element, index).
Split by position Indexes 0–2 go to first; the rest go to rest.
Handy for buckets Use the index when the group depends on position, not only on the value.
Compatibility
Browser & Runtime Support
Object.groupBy() is an ES2024 addition. Support is growing but not universal yet — check typeof Object.groupBy before use.
✓ Newer · ES2024
Object.groupBy()
Available in recent Chrome, Firefox, Safari, and Edge builds. Older browsers need a fallback.
85%Modern browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Object.groupByGood
Bottom line: Confirm support with typeof Object.groupBy === "function". For older engines, group with a loop or use a polyfill.
Frequently Asked Questions
It groups items from an iterable into a plain object. Each callback return value becomes a key, and matching items are stored in an array under that key.
It is relatively new (ES2024). Many modern browsers support it, but you should check typeof Object.groupBy === "function" before relying on it.
Each element and its index: callback(element, index). Return a string or symbol to use as the group key.
Object.groupBy returns a plain object with string/symbol keys. Map.groupBy returns a Map and can use any value as a key.
No. It builds a new object of arrays. The original iterable is left unchanged.