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