Map over object preserving keys

后端 未结 12 1457
再見小時候
再見小時候 2020-12-07 14:41

The map function in underscore.js, if called with a javascript object, returns an array of values mapped from the object\'s values.

_.map({one:          


        
12条回答
  •  甜味超标
    2020-12-07 15:10

    I managed to find the required function in lodash, a utility library similar to underscore.

    http://lodash.com/docs#mapValues

    _.mapValues(object, [callback=identity], [thisArg])
    

    Creates an object with the same keys as object and values generated by running each own enumerable property of object through the callback. The callback is bound to thisArg and invoked with three arguments; (value, key, object).

提交回复
热议问题