Skip to content

Function.countBy

github-actions[bot] edited this page Aug 6, 2026 · 27 revisions

umt / countBy

Function: countBy()

countBy<T, K>(array, iteratee): Record<K, number>

Defined in: Array/countBy.ts:10

Counts elements of an array grouped by an iteratee key

Type Parameters

T

T

K

K extends string | number

Parameters

array

T[]

Array to count

iteratee

(value, index, array) => K

Function to determine the group key for each element

Returns

Record<K, number>

Object mapping keys to counts

Examples

countBy([6.1, 4.2, 6.3], Math.floor); // { '4': 1, '6': 2 }
countBy(["one", "two", "three"], (s) => s.length); // { '3': 2, '5': 1 }

API

Classes

Interfaces

Type Aliases

Variables

Functions

Clone this wiki locally