CountByField
cartographer / countByField
Function: countByField()
Section titled “Function: 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.
Parameters
Section titled “Parameters”Array of items to count
fieldKey
Section titled “fieldKey”string
Field key to count by
Returns
Section titled “Returns”Record<string, number>
- Object with field values as keys and counts as values
Example
Section titled “Example”const counts = countByField(items, 'catalog-status');// { 'raw': 5, 'reviewed': 3, 'approved': 2 }