Transforms an array into a record keyed by the value of key. Later items overwrite earlier items if they share the same key value. Items where the key value is not a valid property key are skipped.
key
The array to transform.
The key whose value becomes the record key.
mapArrayToRecord([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }], "id")// => { 1: { id: 1, name: "Alice" }, 2: { id: 2, name: "Bob" } } Copy
mapArrayToRecord([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }], "id")// => { 1: { id: 1, name: "Alice" }, 2: { id: 2, name: "Bob" } }
Transforms an array into a record keyed by the value of
key. Later items overwrite earlier items if they share the same key value. Items where the key value is not a valid property key are skipped.