Skip to content

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.

T

ArrayToHashParams<T>

The parameters object

ArrayToHashResult<T>

An object keyed by the specified property values

arrayToHash({ array: [{ id: "a", name: "Alice" }], key: "id" });
// => { a: { id: "a", name: "Alice" } }

array to object, keyBy, objectify, index by, lookup table, dictionary

Error if array is not an array

Error if key is not a string