function toObject(arr, keyFunc, opt_obj) {
  const ret = {};
  forEach(arr, function(element, index) {
    ret[keyFunc.call(/** @type {?} */ (opt_obj), element, index, arr)] =
        element;
  });
  return ret;
}
Creates a new object built from the provided array and the key-generation
function.
@param {IArrayLike<T>} arr Array or array like object over
    which to iterate whose elements will be the values in the new object.
@param {?function(this:S, T, number, ?) : string} keyFunc The function to
    call for every element. This function takes 3 arguments (the element, the
    index and the array) and should return a string that will be used as the
    key for the element in the new object. If the function returns the same
    key for more than one element, the value for that key is
    implementation-defined.
@param {S=} opt_obj The object to be used as the value of 'this'
    within keyFunc.
@return {!Object<T>} The new object.
@template T,S