<!-- 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

<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) =&gt; ReturnType


</td><td>

A function to determine the group name of a single item.


</td></tr>
</tbody></table>

**Returns:**

Record&lt;ReturnType, ArrayType\[\]&gt;

The items grouped in a dictionary.

