indexOn
Creates an object from an array, using the specified key and excluding it from each value.
- Use
Array.prototype.reduce()
to create an object fromarr
. - Use object destructuring to get the value of the given
key
and the associateddata
and add the key-value pair to the object.