Created
March 31, 2023 17:08
-
-
Save shameemreza/1c12259e7745cf03776d57a2946b6592 to your computer and use it in GitHub Desktop.
Code for the "How to Render an Array of Objects in React?" Article.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
function EmployeeList() { | |
const employees = [ | |
{ name: "John Doe", age: 25, position: "Software Engineer" }, | |
{ name: "Jane Smith", age: 32, position: "Product Manager" }, | |
{ name: "Mike Johnson", age: 27, position: "UI/UX Designer" }, | |
{ name: "Sarah Lee", age: 30, position: "Marketing Manager" }, | |
]; | |
const employeeList = employees.map((employee) => ( | |
<tr key={employee.name}> | |
<td>{employee.name}</td> | |
<td>{employee.age}</td> | |
<td>{employee.position}</td> | |
</tr> | |
)); | |
return ( | |
<div> | |
<table> | |
<thead> | |
<tr> | |
<th>Name</th> | |
<th>Age</th> | |
<th>Position</th> | |
</tr> | |
</thead> | |
<tbody>{employeeList}</tbody> | |
</table> | |
</div> | |
); | |
} | |
export default EmployeeList; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment