arrayToHash
arrayToHash<
T>(params):ArrayToHashResult<T>
Defined in: arrays/array-to-hash/index.ts:22
Converts an array of objects into a hash map keyed by a specified property.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”params
Section titled “params”ArrayToHashParams<T>
The parameters object
Returns
Section titled “Returns”ArrayToHashResult<T>
An object keyed by the specified property values
Example
Section titled “Example”arrayToHash({ array: [{ id: "a", name: "Alice" }], key: "id" });// => { a: { id: "a", name: "Alice" } }Keywords
Section titled “Keywords”array to object, keyBy, objectify, index by, lookup table, dictionary
Throws
Section titled “Throws”Error if array is not an array
Throws
Section titled “Throws”Error if key is not a string