Options
All
  • Public
  • Public/Protected
  • All
Menu

Module countBy

Index

References

Functions Collection

References

Renames and re-exports countBy

Collection Functions

  • countBy<T>(collection: ArrayLike<T>, iteratee: ArrayIteratee<T, any>): Record<string, number>
  • countBy<T>(collection: Record<string, T>, iteratee: RecordIteratee<T, any>): Record<string, number>
  • Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The corresponding value of each key is the number of times the key was returned by iteratee. The iteratee is invoked with one argument: (value).

    since

    5.7.0

    example
    const users = [
    { 'user': 'barney', 'active': true },
    { 'user': 'betty', 'active': true },
    { 'user': 'fred', 'active': false }
    ]

    countBy(users, value => value.active);
    // => { 'true': 2, 'false': 1 }

    Type parameters

    • T

    Parameters

    • collection: ArrayLike<T>

      The collection to iterate over.

    • iteratee: ArrayIteratee<T, any>

      The iteratee to transform keys.

    Returns Record<string, number>

    Returns the composed aggregate object.

  • Type parameters

    • T

    Parameters

    • collection: Record<string, T>
    • iteratee: RecordIteratee<T, any>

    Returns Record<string, number>