map function for objects (instead of arrays)

前端 未结 30 2434
无人及你
无人及你 2020-11-22 04:23

I have an object:

myObject = { \'a\': 1, \'b\': 2, \'c\': 3 }

I am looking for a native method, similar to Array.prototype.map

30条回答
  •  天涯浪人
    2020-11-22 04:54

    No native methods, but lodash#mapValues will do the job brilliantly

    _.mapValues({ 'a': 1, 'b': 2, 'c': 3} , function(num) { return num * 3; });
    // → { 'a': 3, 'b': 6, 'c': 9 }
    

提交回复
热议问题