Reputation: 7105
I am a getting a json object as a response and console log shows the response like this
MyFormName: Array(5)
0: {question: "Q1", type: "star"}
1: {question: "Q1", type: "star"}
2: {question: "Q1", type: "star"}
3: {question: "Q1", type: "star"}
4: {question: "Q1", type: "star"}
How can i map through this object so i can show data in each object?
I have tried something like this. I have my json object in a state fullForm
and tried the following approach
return Object.keys(this.state.fullForm).map((item, key) => {
return (
<div className="overflow_hidden" key={key}>
<div>{key + 1}</div>
<div>{item.question}</div>
</div>
)
});
But here the value i get for item
is MyFormName
. I want to map the objects in MyFormName
. How can i do this?
Upvotes: 0
Views: 86
Reputation: 6527
this.state.fullForm[Object.keys(this.state.fullForm)[0]].map(item, key) => {
//your logic here
})
It will get you the first item of fullForm which is in this example MyFormName's value as in an array and then you do .map
Upvotes: 1