GroupByArrayField
cartographer / groupByArrayField
Function: groupByArrayField()
Section titled “Function: 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.
Parameters
Section titled “Parameters”Array of items to group
fieldKey
Section titled “fieldKey”string
Array field key to group by
Returns
Section titled “Returns”Map<string | number | boolean, CatalogItem[]>
- Map of field values to arrays of items containing that value
Example
Section titled “Example”const byAuthor = groupByArrayField(items, 'authors');// { 'Lovecraft, H. P.': [item1, item3], 'Smith, Clark Ashton': [item2, item3] }