Function invertBy

  • This method is like invert except that the inverted object is generated from the results of running each element of object thru iteratee. The corresponding inverted value of each inverted key is an array of keys responsible for generating the inverted value. The iteratee is invoked with one argument: (value).

    Type Parameters

    • T = any

    Parameters

    • object: Record<string, T>

      The object to invert.

    • iteratee: RecordIteratee<T, string>

      The iteratee invoked per element.

    Returns Record<string, string[]>

    Returns the new inverted object.

    Since

    5.11.0

    Example

    const object = { 'a': 1, 'b': 2, 'c': 1 }

    invertBy(object, value => `group${value}`)
    // => { 'group1': ['a', 'c'], 'group2': ['b'] }