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.

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

Parameters

{Array} arr
Array or array-like object containing items to group together and count.
{function(*,number,Array)} grouper
Function that will be called for all of the items in arr and will be passed (1) the item, (2) the index within arr and (3) arr. The return value will be used as the property name for which each item in arr will count.
{Object=} opt_initial Optional, Default:{}
Object to augment with property names that will contain counts of how many items correspond to the values returned by grouper.

Returns

{Object}
opt_initial with property names that will contain counts of how many items correspond to the values returned by grouper.

Required Function

This function 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.