4.17.11
3.10.1
2.4.2
1.3.1

_.mapValues(object, [iteratee=_.identity])

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

argument
object
[iteratee=_.identity]
type
Object
Function
description
The object to iterate over.
The function invoked per iteration.

Returns

(array)

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)

// The `_.property` iteratee shorthand.
_.mapValues(users, "age");
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
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)

// The `_.property` iteratee shorthand.
_.mapValues(users, "age");
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)