const arrayToObject = (arr, keyField) => Object.assign({}, ...arr.map(item => ({[item[keyField]]: item})))
Rewriting Javascript: Converting an Array of Objects to an Object.
Chris Burgin
47921

Chris Burgin:

What’s the advantage of using the `Object.assign()` ?

Seems like you can do just

const arrayToObject = (arr = [], key = 'id') => arr.reduce((res, item) => ({ ...res, [item[key]]: item }), {});