I need to display "details" array from the list array. How do I correctly access it using map() function?
With list.map() I am able to map first level items, but couldn't find a solution for second level of the array.
output can be as below:
1 John, 18, 180
2 Don, 20, 170
3 Mr White, 28, 170
Code:
import React, { Component } from 'react';
class App extends Component {
constructor(props) {
super(props);
this.state = {
list: [
{
id:1,
name:'John',
details: [
{
id:1,
age:18,
height:180
}
]
},
{
id:2,
name:'Don',
details: [
{
id:3,
age:20,
height:170
}
]
},
{
id:3,
name:'Mr White',
details: [
{
id:3,
age:28,
height:190
}
]
}
],
};
}
render() {
return (
<div>
<ul>
{this.state.list.map((item1) => (
<p key={item1.id}>{item1.id} {item1.name}</p>
))}
</ul>
</div>
);
}
}
export default App;