map function for objects (instead of arrays)

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

    First, convert your HTMLCollection using Object.entries(collection). Then it’s an iterable you can now use the .map method on it.

    Object.entries(collection).map(...)
    

    reference https://medium.com/@js_tut/calling-javascript-code-on-multiple-div-elements-without-the-id-attribute-97ff6a50f31

提交回复
热议问题