mapValues source npm
_.mapValues(object, [iteratee=_.identity])
Creates an object with the same keys as object
and values generated by
running each own enumerable property of object
through iteratee
. The
iteratee function is invoked with three arguments: (value, key, object).
Arguments
- object (Object)
The object to iterate over.
- [iteratee=_.identity] (Function|Object|string)
The function invoked per iteration.
Returns (Object)
Returns the new mapped object.
Example
var users = {
'fred': { 'user': 'fred', 'age': 40 },
'pebbles': { 'user': 'pebbles', 'age': 1 }
};
_.mapValues(users, function(o) { return o.age; });
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
// using the `_.property` callback shorthand
_.mapValues(users, 'age');
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)