const robots = [
{
id: 1,
name: 'Leanne Graham',
username: 'Bret',
},
{
id: 2,
name: 'Ervin Howell',
username: 'Antonette',
},
{
id: 3,
name: 'Clementine Bauch',
username: 'Samantha',
},
{
id: 4,
name: 'Patricia Lebsack',
username: 'Karianne',
},
{
id: 5,
name: 'Chelsey Dietrich',
username: 'Kamren',
},
{
id: 6,
name: 'Mrs. Dennis Schulist',
username: 'Leopoldo_Corkery',
},
{
id: 7,
name: 'Kurtis Weissnat',
username: 'Elwyn.Skiles',
},
{
id: 8,
name: 'Nicholas Runolfsdottir V',
username: 'Maxime_Nienow',
},
{
id: 9,
name: 'Glenna Reichert',
username: 'Delphine',
},
{
id: 10,
name: 'Clementina DuBuque',
username: 'Moriah.Stanton',
}
];
let cardComp = robots.forEach((element,index)=> {
return (<Card id = {robots[index].id} Name = {robots[index].name}
user ={robots[index].username} mail = {robots[index].email}/>)
});
The following Code is not working in react.js But the same code when I replace the forEach loop with maps works fine. Why does it not work with the forEach loop? When I try to get the value from the array of objects using normal javascript, it works just fine and I am able to get all the values in the array. But it's not working in the react.js with a forEach loop.