• Groups the elements of an array based on the given function

    Example

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

    Example

    groupBy(['one', 'two', 'three'], 'length'); // {3: ['one', 'two'], 5: ['three']}
    

    Type Parameters

    • T

    Parameters

    • array: T[]
    • fn: string | ((item: T, index: number, array: T[]) => any)

    Returns Record<string, T[]>

Generated using TypeDoc