Skip to content

GroupByArrayField

cartographer


cartographer / groupByArrayField

groupByArrayField(items, fieldKey): Map<string | number | boolean, CatalogItem[]>

Defined in: queries/queryFunctions.ts:385

Group items by array field values (items can belong to multiple groups).

Each value in an array field creates a separate group. Items with multiple values appear in multiple groups.

CatalogItem[]

Array of items to group

string

Array field key to group by

Map<string | number | boolean, CatalogItem[]>

  • Map of field values to arrays of items containing that value
const byAuthor = groupByArrayField(items, 'authors');
// { 'Lovecraft, H. P.': [item1, item3], 'Smith, Clark Ashton': [item2, item3] }