Function groupBy

  • Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The order of grouped values is determined by the order they occur in collection. The corresponding value of each key is an array of elements responsible for generating the key. The iteratee is invoked with one argument: (value).

    Type Parameters

    • T

    Parameters

    • result: Collection<T>

    Returns Record<string, T[]>

    Returns the composed aggregate object.

    Since

    5.5.0

    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

    • result: ArrayLike<T>
    • iteratee: KeyIteratee

    Returns Record<string, T[]>

  • Type Parameters

    • T

    Parameters

    • result: Record<string, T>
    • iteratee: KeyIteratee

    Returns Record<string, T[]>

  • Type Parameters

    • T

    Parameters

    • result: ArrayLike<T>
    • iteratee: ArrayIteratee<T, any>

    Returns Record<string, T[]>

  • Type Parameters

    • T

    Parameters

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

    Returns Record<string, T[]>