On this page
Object.groupBy
Prev: freeze | Up: Object | Next: is
Rel: Object, Object & Reflect Guide
Ref: MDN Web Docs — Object.groupBy
Tags: #public #web #javascript #builtins #object #tier/standard
Signature & Overview
Object.groupBy(items, callbackFn)
Groups elements of an iterable into a null-prototype object keyed by callbackFn(item, index) (ES2024).
Notes & Pitfalls
- ES2024 null-prototype object grouping: Keys are coerced to strings/symbols; use
Map.groupBy()if you need non-string keys.
Example
const items = [{ type: "fruit", name: "apple" }, { type: "veg", name: "pea" }];
const grouped = Object.groupBy(items, (x) => x.type);
console.assert(grouped.fruit.length === 1);
Linked from
Related notes
- tuts/javascript/builtins/Object/freeze Linked here; links to this page; shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object/is Linked here; links to this page; shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object Linked here; links to this page; shared tags: #builtins, #javascript, #object, #web
- tuts/javascript/builtins/object_and_reflect Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/Object/assign shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object/create shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object/defineProperty shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object/entries shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object/fromEntries shared tags: #builtins, #javascript, #object, #tier, #web
- tuts/javascript/builtins/Object/getPrototypeOf shared tags: #builtins, #javascript, #object, #tier, #web