@empathyco/x-components
Version:
Empathy X Components
28 lines (16 loc) • 977 B
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [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) => ReturnType | A function to determine the group name of a single item. |
**Returns:**
Record<ReturnType, ArrayType\[\]>
The items grouped in a dictionary.