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