const course = [{
id: 1,
name: 'Half Stack application development',
parts: [
{
name: 'Fundamentals of React',
exercises: 10,
id: 1
},
{
name: 'Using props to pass data',
exercises: 7,
id: 2
},
{
name: 'State of a component',
exercises: 14,
id: 3
}
]
},
{
name: 'Node.js',
id: 2,
parts: [
{
name: 'Routing',
exercises: 3,
id: 1
},
{
name: 'Middlewares',
exercises: 7,
id: 2
}
]
}
]
I have found it is easy to map the names "Half Stack Application Development" and "Node.js" and displaying them by doing:
{course.map(c => <li>{c.name}</li>)}
However, course.parts.map(c => <li>{c.name}</li>) returns undefined.
How would you map it so it looks like
Half Stack Application Development
- Fundamentals of react
- Using props to pass data
- State of a component
Node.js
- Routing
- Middleware
Why does course.parts.map(p => p.name) return undefined and how can you access the names in the parts array?
courseis an array. It doesn't have apartsproperty. Every element within the array has apartsproperty. It's not clear how exactly you want the output to be in this case, given that there is more than one part per course.