API Reference

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

function getKeyValueCounts<T extends object, U extends keyof T>(
  arr: T[],
  key: U,
  isCaseSensitive = false
)

// Example:

const arr = [{ name: "John"}, { name: "Sarah"}, { name: "John"}, { name: "Beth"}]

getKeyValueCounts(arr, "name") //=> { John: 2, Sarah: 1, Beth: 1 }