map function for objects (instead of arrays)

前端 未结 30 2696
无人及你
无人及你 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 05:03

    I specifically wanted to use the same function that I was using for arrays for a single object, and wanted to keep it simple. This worked for me:

    var mapped = [item].map(myMapFunction).pop();
    

提交回复
热议问题