Skip to content

CountByField

cartographer


cartographer / countByField

countByField(items, fieldKey): Record<string, number>

Defined in: queries/queryFunctions.ts:79

Count unique items grouped by a field value.

Returns a map of each unique field value to the count of items with that value.

CatalogItem[]

Array of items to count

string

Field key to count by

Record<string, number>

  • Object with field values as keys and counts as values
const counts = countByField(items, 'catalog-status');
// { 'raw': 5, 'reviewed': 3, 'approved': 2 }