企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## mapValues + [link](./mapValues "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L11442 "View in source.") + [npm](https://www.npmjs.com/package/lodash.mapvalues "See the npm package.") ``` _.mapValues(object, [iteratee=_.identity]) ``` 创建一个对象,对象的key相同,值是通过 `iteratee` 产生的。 iteratee 会传入3个参数: (value, key, object) ### 参数 1. object (Object) 要遍历的对象 2. [iteratee=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (Object) 返回映射后的对象 ### 示例 ``` var users = { 'fred': { 'user': 'fred', 'age': 40 }, 'pebbles': { 'user': 'pebbles', 'age': 1 } }; _.mapValues(users, function(o) { return o.age; }); // => { 'fred': 40, 'pebbles': 1 } (无法保证遍历的顺序) // 使用了 `_.property` 的回调结果 _.mapValues(users, 'age'); // => { 'fred': 40, 'pebbles': 1 } (无法保证遍历的顺序) ```