Function keyBy

  • 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 last element responsible for generating the key. The iteratee is invoked with one argument: (value).

    Type Parameters

    • T

    Parameters

    • collection: T[]

      The collection to iterate over.

    • iteratee: ((value: T) => string)

      The iteratee to transform keys.

        • (value): string
        • Parameters

          • value: T

          Returns string

    Returns Dictionary<T>

    Returns the composed aggregate object.

    4.0.0

    groupBy, partition

    const array = [
    { 'dir': 'left', 'code': 97 },
    { 'dir': 'right', 'code': 100 }
    ]

    keyBy(array, ({ code }) => String.fromCharCode(code))
    // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }