@empathyco/x-components
Version:
Empathy X Components
28 lines (16 loc) • 1.18 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [arrayToObject](./x-components.arraytoobject_1.md)
## arrayToObject() function
Reduce an array of objects to an object which properties names are the value of each object\[key\], and the value under that property are each object. 'key' is the the parameter passed to this function.
**Signature:**
```typescript
export declare function arrayToObject<ArrayType>(array: ArrayType[], key: PropsWithType<ArrayType, string | number>): Record<string, ArrayType>;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| array | ArrayType\[\] | Array of objects that contains objects which have object\[key\] string as a property value. |
| key | [PropsWithType](./x-components.propswithtype.md)<!-- --><ArrayType, string \| number> | Key used to access to each object\[key\] value, used for each property name in the new object. |
**Returns:**
Record<string, ArrayType>
New object which properties object\[key\] contains object of each iteration in the array.