On this page
  1. Object.groupBy
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

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

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