forEach over es6 Map in JSX

后端 未结 4 2018
情深已故
情深已故 2021-02-19 02:22

I had a javascript array that was rendering components using array.map. I switched this array to an es6 Map in order to be able to use key-value pairs

4条回答
  •  执念已碎
    2021-02-19 02:50

    If you call .entries() on your map you will get an iterator object which for every key/value pair contains an array with the structure: [key, value] as mentioned here.

    So you could just do:

    {resultsByGuid.entries().map((result) => { return this.renderGalleryItem(result[1], result[0]); })}

    I am still wondering, if there's a simpler solution though.

提交回复
热议问题