@empathyco/x-components
Version:
Empathy X Components
73 lines (34 loc) • 1.16 kB
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
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
array
</td><td>
ArrayType\[\]
</td><td>
The array to iterate, grouping its items in different arrays based on the `groupBy` function.
</td></tr>
<tr><td>
groupBy
</td><td>
(item: ArrayType, index: number) => ReturnType
</td><td>
A function to determine the group name of a single item.
</td></tr>
</tbody></table>
**Returns:**
Record<ReturnType, ArrayType\[\]>
The items grouped in a dictionary.