@empathyco/x-components
Version:
Empathy X Components
73 lines (34 loc) • 1.37 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
<table><thead><tr><th>
Parameter
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
array
</td><td>
ArrayType\[\]
</td><td>
Array of objects that contains objects which have object\[key\] string as a property value.
</td></tr>
<tr><td>
key
</td><td>
[PropsWithType](./x-components.propswithtype.md)<!-- --><ArrayType, string \| number>
</td><td>
Key used to access to each object\[key\] value, used for each property name in the new object.
</td></tr>
</tbody></table>
**Returns:**
Record<string, ArrayType>
New object which properties object\[key\] contains object of each iteration in the array.