.invertBy(object, [iteratee=.identity])
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
object
(Object): The object to invert.[iteratee=.identity]
(Function)_: The iteratee invoked per element.
Returns
(Object): Returns the new inverted object.
Example
var object = { 'a': 1, 'b': 2, 'c': 1 };_.invertBy(object);// => { '1': ['a', 'c'], '2': ['b'] }_.invertBy(object, function(value) {return 'group' + value;});// => { 'group1': ['a', 'c'], 'group2': ['b'] }
当前内容版权归 lodash.com 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 lodash.com .