Skip to main content

invertBy

_.invertBy(iteratee, object) # Ⓢ [Ⓣ][1] Ⓝ

This method is like _.invert except that the inverted object is generated



from the results of running each element of object thru iteratee. The



corresponding inverted value of each inverted key is an array of keys



responsible for generating the inverted value. The iteratee is invoked



with one argument: (value).

Since​

4.1.0

Arguments​

  1. iteratee (Function): The iteratee invoked per element.
  2. object (Object): The object to invert.

Returns​

(Object): Returns the new inverted object.

Example​

var object = { 'a': 1, 'b': 2, 'c': 1 };

_.invertBy(_.identity, object);
// => { '1': ['a', 'c'], '2': ['b'] }

_.invertBy(function(value) {
return 'group' + value;
}, object);
// => { 'group1': ['a', 'c'], 'group2': ['b'] }