codecamp

Lodash _.mapValues

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

创建一个对象,这个对象的key与object对象相同,值是通过 iteratee 运行 object 中每个自身可枚举属性名字符串产生的。 iteratee调用三个参数: (value, key, object)。

添加版本

2.4.0

参数

  1. object (Object): 要遍历的对象。
  2. [iteratee=_.identity] (Function): 每次迭代时调用的函数。

返回

(Object): 返回映射后的新对象。

例子

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)


Lodash _.mapKeys
Lodash _.merge
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

Lodash 简介

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }