The use case is to convert an array of objects into a hash map based on string or function provided to evaluate and use as the key in the hash map and val
A small improvement on the reduce usage:
reduce
var arr = [ { key: 'foo', val: 'bar' }, { key: 'hello', val: 'world' } ]; var result = arr.reduce((map, obj) => ({ ...map, [obj.key] = obj.val }), {}); console.log(result); // { foo: 'bar', hello: 'world' }