0

I need this thing into a loop or map.please help. I don't want to provide the index number for arrays.

<div id="question"> {this.props.questions[0].id} :- {this.props.questions[0].text} <h3>Correct Answer:- {this.props.questions[0].correct}</h3> <h3>Your Answer:- {this.props.useranswer[0]}</h3> </div> 

2 Answers 2

2

Try the below render() method with map function:

render() { const { questions, useranswer } = this.props; return( questions.map((question, i)=> <div id="question"> {question.id} :- {question.text} <h3>Correct Answer:- {question.correct}</h3> <h3>Your Answer:- {useranswer[i]}</h3> </div> ) ) } 
Sign up to request clarification or add additional context in comments.

Comments

0
You use the map function in the render() function. Like { this.props.questions.map((question)=>{ <div id="question"> {question.id} :- {question.text} <h3>Correct Answer:- {question.correct}</h3> <h3>Your Answer:- {get answer from question id}</h3> </div> )} 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.