render an array in react code example
Example 1: map function in react
function NameList() {
const names = ['Bruce', 'Clark', 'Diana']
return (
<div>
{names.map(name => <h2>{name}</h2>)}
</div>
)
}
Example 2: rendering an array inside an array in react
list.map((item, index) => {
return (
<div key={index}>
<ul >{item.value}</ul>
{
item.list.map((subitem, i) => {
return (
<ul ><li>{subitem.value}</li></ul>
)
})
}
</div>
)
}