groupBy()

Takes an array and groups the items together based on a given hasher function.

This function is valid in v2.12.0 to v2.24.3. This function has been downloaded 63 times.

Parameters

{Array} arr
Array containing the items to be grouped by the hasher function.
{Function|Array|string} hasher
If a function, it will be passed a value which will be used to group the items in arr. If an array or a string it will be seen as the path within each item in arr to the property by which to group each item.
{*=} opt_initial Optional, Default:{}
Object that will be augmented and returned. The values at the keys produced by hasher will be arrays containing all of the corresponding items from arr. If not specified the default is a new empty object.

Returns

{*}
opt_initial with all of the keys specified by hasher corresponding to arrays containing those values that come from arr.

Required Function

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

  • countBy()
    Creates or augments an object, making new properties that correspond to values in the given array. Each property added will indicate how many items in the array corresponding to those property names.

Requiring Function

This function is directly required by the following function:

  • countBy()
    Creates or augments an object, making new properties that correspond to values in the given array. Each property added will indicate how many items in the array corresponding to those property names.