• Converts an array to an object whose keys are generated via the predicate function

    Type Parameters

    • T extends Record<string, any>

    Parameters

    • data: T[]
    • predicate: ((item) => string)

      Receives the data at each array index and returns a string that is used as the object key

        • (item): string
        • Parameters

          • item: T

          Returns string

    Returns Record<string, T>

    {Record<string, T>}

    Example

    categoriseArrayByObjectPropertyName([ { 'name': 'andy', 'age': 27 }, { 'name': 'bob', 'age': 30 } ], 'name');
    // return { 'andy': { 'name': 'andy', 'age': 27 }, 'bob': { 'name': 'bob', 'age': 30 } }

Generated using TypeDoc