UNPKG

@empathyco/x-components

Version:
28 lines (16 loc) 977 B
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [groupItemsBy](./x-components.groupitemsby.md) ## groupItemsBy() function Groups the array items based on the provided `groupBy` function. **Signature:** ```typescript export declare function groupItemsBy<ArrayType, ReturnType extends string | number>(array: ArrayType[], groupBy: (item: ArrayType, index: number) => ReturnType): Record<ReturnType, ArrayType[]>; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | array | ArrayType\[\] | The array to iterate, grouping its items in different arrays based on the <code>groupBy</code> function. | | groupBy | (item: ArrayType, index: number) =&gt; ReturnType | A function to determine the group name of a single item. | **Returns:** Record&lt;ReturnType, ArrayType\[\]&gt; The items grouped in a dictionary.