dtracers
dtracers

Reputation: 1658

How to render a Map in typescript

I see lots of people converting data to arrays with methods not possible to me as far as I can see.

I am using react and typescript and have a very simple map that I wish to render as a list of buttons

Here is what I have so far

const renderPlayerChoice = (indexMap: Map<number, number>) => {
    // What I would like to do if it was possible
    return indexMap.map((key, value =>{
    // do stuff here
    return stuff
    }) 
}

But the map function does not exist for this object it only has a foreach which does not return any results

Upvotes: 0

Views: 1481

Answers (1)

serg06
serg06

Reputation: 2705

Like so:

return Array.from(indexMap).map(([key, value]) => {
    // do stuff here
    return stuff;
});

Upvotes: 1

Related Questions