map function for objects (instead of arrays)

前端 未结 30 2695
无人及你
无人及你 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:56

    I came here looking to find and answer for mapping an object to an array and got this page as a result. In case you came here looking for the same answer I was, here is how you can map and object to an array.

    You can use map to return a new array from the object like so:

    var newObject = Object.keys(myObject).map(function(key) {
       return myObject[key];
    });
    

提交回复
热议问题