Function groupBy

  • Creates an object composed of keys generated from the results of running each element of arr thru func. The order of grouped values is determined by the order they occur in arr. The corresponding value of each key is an array of elements responsible for generating the key.

    Returns

    Returns the aggregated object.

    Example

    groupBy([6.1, 4.2, 6.3], Math.floor)
    // { '4': [4.2], '6': [6.1, 6.3] }

    // The `property` iteratee shorthand.
    groupBy(['one', 'two', 'three'], 'length')
    // { '3': ['one', 'two'], '5': ['three'] }

    Type Parameters

    • T

    Parameters

    • arr: Iterable<T>

      The collection to iterate over.

    • fn: Iteratee<T, any, any>

    Returns Record<PropertyKey, T[]>

  • Type Parameters

    • T

    Parameters

    • arr: Iterable<T>
    • fn: PropertyKey

    Returns Record<PropertyKey, T[]>

  • Type Parameters

    • T

    Parameters

    • arr: Object
    • fn: Iteratee<T, any, any>

    Returns Record<PropertyKey, T[]>

  • Type Parameters

    • T

    Parameters

    • arr: Object
    • fn: PropertyKey

    Returns Record<PropertyKey, T[]>

Generated using TypeDoc