JavaScript 2025 · Arrays

Group items by a property

Return an object whose keys are the group names. Available in current browsers and Node.js 21 and later.

const byRole = Object.groupBy(users, (user) => user.role);

Official JavaScript 2025 documentation

More arrays commands

All arrays commands · JavaScript 2025 cheatsheet

Was this page helpful?