Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
38
rated 0 times [  39] [ 1]  / answers: 1 / hits: 16726  / 7 Years ago, mon, march 20, 2017, 12:00:00

Heading Does anyone know how can I map a dictionary in React js ?


export class ServiceFeatures extends React.Component {
constructor(props) {
super(props)
this.state = {dict: {'awesome': ['wow','alo'], 'great': ['ano', 'alo' ]}}
}

render() {
return (
<div>
{this.state.dict.map((name, features) => (
<Services categories={features}></Services>
))}
</div>
)
}

}


More From » reactjs

 Answers
42

You can map over the keys of an object using Object.keys.



return (
<div>
{
Object.keys(this.state.dict).map(name => (
<Services categories={this.state.dict[name]}></Services>
))
}
</div>
)

[#58477] Friday, March 17, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
finn

Total Points: 154
Total Questions: 88
Total Answers: 82

Location: Lithuania
Member since Mon, Nov 16, 2020
4 Years ago
;