UNPKG

@empathyco/x-components

Version:
73 lines (34 loc) 1.37 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [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)<!-- -->&lt;ArrayType, string \| number&gt; </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&lt;string, ArrayType&gt; New object which properties object\[key\] contains object of each iteration in the array.