Map an array of keys into a new object.
yarn add keys-to-object
Takes an array of keys and a map to generate corresponding values, and builds a new object from them.
If the key values themselves are arrays, the created object will be nested.
keysToObject<K, V>(
keys: K[],
valueMap: V | (key: K, index: number) => V,
keyMap?: (key: K, index: number) => string | string[],
initial?: object
): object
The array of keys to map.
The value generated for each key, either a constant or a function of the key and index.
(Optional) A map to modify the keys of the result object.
(Optional) The object the new keys and values will be assigned to. Defaults to a new empty object.