I want to create a list of card views from the data received from API. For example, I have a student object. I want to create a card where student name student time and student class and also one button to admit student in class on the same card. I am new to react js.
Asked
Active
Viewed 885 times
-1
-
1Please edit your question to include a [Minimal, Complete, and Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). Generally you would store the fetched data in an array and use `array.prototype.map` to map the data to the JSX you want rendered. See [Lists & Keys](https://reactjs.org/docs/lists-and-keys.html). I suggest referring to official React docs for just about any question you have, they are very informative and well maintained. – Drew Reese Jan 11 '21 at 08:21
1 Answers
0
Loop through your array of students and render a card for each student as following using foreach array method , you can choose another methods to loop through your array:
StudentsArray.forEach((element))=>{
return(
<Card name={element.name} id={element.id}/>
)
}
Check for each loop reference Array.prototype.foreach()
for more check this out loop through an array in javascript
Update: ForEach does not return any value. use map() instead as the following example: Array.map()

Hassan Kandil
- 1,612
- 1
- 13
- 26
-
2ForEach does not return any value. https://www.w3schools.com/jsref/jsref_foreach.asp – Swaraj Gandhi Jan 11 '21 at 08:20