indexBy()

Traverses an array and returns an object with the values from the array placed in the specified indices.

This function is valid in v2.1.0 to v2.11.0. This function has been downloaded 0 times.

Parameters

{Array} arr
Values to be placed in the returned object.
{function(*,number,Array)} indexer
Function that will be called for each item in arr and return an index that will be the property name under which the value will be found in the returned object. If the same index is returned multiple times the last value corresponding to that index will be the one found in the returned object. The values passed to this function will be (1) the arr item, (2) the index in arr at which the item is found, and (3) arr.
{Object=} opt_initial Optional, Default:{}
The object that will be augmented and returned.

Returns

{Array}
opt_initial with additional properties names coming from the return values of indexer and the items found in arr.

Required Function

This function directly requires the following function which is included automatically:

  • has()
    Every object descended from Object inherits the hasOwnProperty method. This method can be used to determine whether an object has the specified property as a direct property of that object; unlike the in operator, this method does not check down the object's prototype chain.