Docly Developers
Function Updated 17 Oct 2026

Array.groupBy(key)

Docly-specific — not part of standard JavaScript (standard JavaScript has Object.groupBy(), which HashJS does not support). Groups the items of an array by a property name or by the value a function returns.

Parameters

keystring | functionrequired

A property name, or a function called with (item) that returns the group key. With a property name, an item that lacks the property throws an error.

Returns

An object where each key is a group and each value is an array of the items in that group.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
const words = ["abcdefg", "efgha", "abc123"];
const groupedByFirstLetter = words.groupBy(word => word[0]);
write(JSON.stringify(groupedByFirstLetter));