Reactopia
ProductsBrowseAboutContact
Products
ProductsBrowseAbout
Yash Mahajan

Reactopia

Workflow products (Migrate, Verify, Release), plus Browse, SVG tools, and Discover. Built by Yash Mahajan.

Product

  • Workflow products
  • Migrate
  • Verify
  • Release
  • Components
  • Discover
  • SVG tools
  • Platform roadmap

Legal

  • Privacy Policy
  • Terms of Use
  • Cookie Policy
  • License
  • Credits
  • Contact

More

  • Discover
  • SVG tools
  • Changelog
  • Contact

Project

  • About
  • Changelog
  • GitHub
  • X

© 2026 Reactopia. All rights reserved.

PrivacyTermsCookies

Getting Started

IntroductionContributing

Components

SeparatorUiButtonBadgeStackUiInputIn devUiSelectIn devUiTextareaIn dev

Hooks

useDebounceuseLocalStorageuseMediaQueryuseMounted

Utilities

cngroupBysleep
Components
groupBy

groupBy

Group an array by key or selector function.

LiveutilityReact, Web, React NativeUpdated 2026-10-07MIT LicenseSource on GitHubReport Issue
cnsleep

Introduction

Group an array of objects by a key or selector function. No dependencies.

Platform: TypeScript / JavaScript (any environment).

Utility

export function groupBy<T, K extends string | number | symbol>(
items: T[],
keyFn: (item: T) => K
): Record<K, T[]> {
return items.reduce(
(acc, item) => {
const key = keyFn(item);
(acc[key] ??= []).push(item);
return acc;
},
{} as Record<K, T[]>
);
}

Example

ts
const byStatus = groupBy(tasks, (t) => t.status);

Footer

For large lists, consider indexing once and reusing the map instead of regrouping on every render.