mapObject
Maps the values of an array to an object using a function.
- Use
Array.prototype.reduce()to applyfnto each element inarrand combine the results into an object. - Use
elas the key for each property and the result offnas the value.
Maps the values of an array to an object using a function.
Array.prototype.reduce() to apply fn to each element in arr and combine the results into an object.el as the key for each property and the result of fn as the value.