Library API
    Preparing search index...

    Function byKey

    • Groups an array of objects by the return value of a callback function.

      Type Parameters

      Parameters

      • arr: T[]

        The array of objects to group

      • grpFn: GroupFn<T>

        The callback function returning the group key

      Returns Record<PropertyKey, T[]>

      A record containing arrays of grouped objects

      const groups = byKey([{ id: 1, type: 'A' }, { id: 2, type: 'A' }], itm => itm.type);
      
    • Groups an array of objects by a sequence of key fields.

      Type Parameters

      Parameters

      • arr: T[]

        The array of objects to group

      • key1: keyof T
      • ...keys: (keyof T)[]

        The sequence of object keys to group by

      Returns Record<PropertyKey, T[]>

      A record containing arrays of grouped objects

      const groups = byKey(users, 'department', 'role');
      
    • Groups an array of objects by the return value of a callback function.

      Type Parameters

      Parameters

      • arr: T[]

        The array of objects to group

      • ...keys: (keyof T)[]

      Returns Record<PropertyKey, T[]>

      A record containing arrays of grouped objects

      const groups = byKey([{ id: 1, type: 'A' }, { id: 2, type: 'A' }], itm => itm.type);