indexBy
Creates an object from an array, using a function to map each value to a key.
- Use
Array.prototype.reduce()
to create an object fromarr
. - Apply
fn
to each value ofarr
to produce a key and add the key-value pair to the object.
Creates an object from an array, using a function to map each value to a key.
Array.prototype.reduce()
to create an object from arr
.fn
to each value of arr
to produce a key and add the key-value pair to the object.