For grouping an array of objects by a property, use Object.groupBy(items, item => item.property) when the group names are property keys; use Map.groupBy(items, callback) when keys may be arbitrary values such as object identities. These built-in static methods now provide the natural comparison point for any custom JavaScript groupBy library. Their design also offers a practical lesson for library authors: a familiar prototype method can create compatibility problems in code already running on the web.
How do I group an array of objects by a property in JavaScript?
Given objects with a type property, Object.groupBy collects items with the same callback result into arrays:
const inventory = [
{ name: "apple", type: "fruit" },
{ name: "pear", type: "fruit" },
{ name: "carrot", type: "vegetable" }
];
const grouped = Object.groupBy(inventory, item => item.type);
console.log(grouped.fruit);
// [{ name: "apple", type: "fruit" }, { name: "pear", type: "fruit" }]
The callback receives each item and its index, and runs once per item. The result is a new grouping container holding arrays of the original item references; the records themselves are not deep-copied. The method accepts an iterable, not only arrays. See MDN’s Object.groupBy reference and the ECMAScript proposal specification.
Choose Object.groupBy or Map.groupBy based on the key
| Method | Result | Key behavior | Use it when |
|---|---|---|---|
Object.groupBy(items, callback) |
A null-prototype object whose properties hold arrays | The callback result is coerced to a property key | Groups are naturally addressed by string-like or symbol property keys |
Map.groupBy(items, callback) |
A Map whose values are arrays |
Keys can be arbitrary values, including object references | You need keys that are not property keys, especially object identity |
For example, if records refer to owner objects and you want to group by those exact objects:
#1 Best Overall
const byOwner = Map.groupBy(records, record => record.owner);
const ownerRecords = byOwner.get(ownerObject);
Object keys in a Map are matched by identity. Looking up a group with a newly created object that merely has the same properties will not find the group; use the same reference returned by, or passed to, the grouping logic. More detail is in MDN’s Map.groupBy reference.
What Object.groupBy returns—and what to watch for
The object returned by Object.groupBy has no Object.prototype in its prototype chain. It therefore does not inherit methods such as toString or hasOwnProperty. Access known groups directly, or use appropriate object utilities when enumerating or checking properties; do not treat the result as an ordinary object with inherited methods.
Rank #2
This null-prototype result also avoids accidental collisions with inherited object property names. TC39’s proposal describes it this way: “The first returns a null-prototype object, which allows ergonomic destructuring and prevents accidental collisions with global Object properties.” The statement appears in the TC39 Array Grouping proposal.
Why JavaScript uses static grouping methods
It might seem more convenient to call a method on an array, such as items.groupBy(callback). The TC39 proposal explains why the standardized APIs instead use Object.groupBy and Map.groupBy: changing built-in prototypes can collide with behavior already present in deployed libraries and applications.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →In particular, the proposal records that older versions of Sugar conditionally installed an incompatible Array.prototype.groupBy. It also notes that Array.prototype.group conflicted with code that used arrays as arbitrary hash maps. The proposal says its investigation found roughly 660 origins using the incompatible Sugar versions; that is a count reported in the proposal’s undated repository text, not a current measurement. Choosing static methods was a way to avoid another web-compatibility hazard. This is a useful constraint for anyone designing a library: API familiarity matters, but so does the behavior of code that already exists.
Are Object.groupBy and Map.groupBy supported in your target runtime?
MDN describes both APIs as widely available across browsers since March 2024. That is broad browser availability, not a guarantee for every older browser or JavaScript runtime. Check the browsers and runtime versions your project actually supports before replacing a dependency or using the methods directly.
Rank #4
- MDN Object.groupBy lists browser compatibility information; its reference page was last modified July 10, 2025.
- MDN Map.groupBy provides compatibility details for the Map method.
- Can I Use’s Object.groupBy table reports 93.25% global usage coverage using StatCounter usage-share data for August 2026. This is a time- and geography-sensitive coverage estimate, not a universal guarantee or a measure of how many developers use the API.
If some supported targets lack the methods, consider a polyfill or retain a custom implementation. The TC39 proposal points to core-js, and MDN’s Object.groupBy reference also lists core-js and es-shims options. Choose based on the exact target matrix and package requirements; the sources cited here do not establish current package versions or runtime-specific release floors.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What a custom groupBy library still needs to decide
Native methods cover the basic grouping operation, but evaluating or designing a library still means checking how its contract fits the application. Compare the output container, accepted keys and coercion rules, whether it accepts general iterables, the callback arguments, handling of special property names and inherited properties, and compatibility with target runtimes. A custom library may also carry a dependency or polyfill cost.
Recommended Free Tools
Best Value
Do not assume a custom implementation or a native method is faster without comparable, reproducible measurements for your workload. The standards and compatibility sources establish API behavior and the reason for the static design; they do not establish performance rankings.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




