Skip to main content

groupBy

_.groupBy(iteratee, collection) # Ⓢ [Ⓣ][1] Ⓝ

Creates an object composed of keys generated from the results of running



each element of collection thru iteratee. The order of grouped values



is determined by the order they occur in collection. The corresponding



value of each key is an array of elements responsible for generating the



key. The iteratee is invoked with one argument: (value).

Since​

0.1.0

Arguments​

  1. iteratee (Function): The iteratee to transform keys.
  2. collection (Array|Object): The collection to iterate over.

Returns​

(Object): Returns the composed aggregate object.

Example​

_.groupBy(Math.floor, [6.1, 4.2, 6.3]);
// => { '4': [4.2], '6': [6.1, 6.3] }

// The `_.property` iteratee shorthand.
_.groupBy('length', ['one', 'two', 'three']);
// => { '3': ['one', 'two'], '5': ['three'] }