Type of elements within the source iterable.
Type produced by keySelector.
A sequence of key/count pairs describing how many elements share each key.
const products = [
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
];
const countByCategory = countBy(products, p => p.category).toArray();
console.log(countByCategory);
// [
// { key: 'Fruit', value: 2 },
// { key: 'Vegetable', value: 1 }
// ]
Counts the occurrences of elements grouped by a derived key.