API Reference

Returns an object with counts of specific values of a shared key in an array of objects.

function keyValueCounts<T extends object, U extends keyof T>( arr: T[], key: U, isCaseSensitive = false ) // Example: const arr = [{ name: "John"}, { name: "Sarah"}, { name: "John"}, { name: "Beth"}] keyValueCounts(arr, "name") //=> { John: 2, Sarah: 1, Beth: 1 }