invert source npm

_.invert(object, [multiVal])

Creates an object composed of the inverted keys and values of object. If object contains duplicate values, subsequent values overwrite property assignments of previous values unless multiVal is true.

Arguments

  1. object (Object)

    The object to invert.

  2. [multiVal] (boolean)

    Allow multiple values per key.

Returns (Object)

Returns the new inverted object.

Example

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

_.invert(object);
// => { '1': 'c', '2': 'b' }

// with `multiVal`
_.invert(object, true);
// => { '1': ['a', 'c'], '2': ['b'] }