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
keyand the associateddataand add the key-value pair to the object.