The object looks like this:
My App.js file looks like this
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: "Redux",
exercises: 11,
id: 4,
},
],
};
return <Course course={course} />;
And I want to total number of exercises filtered into total
const parts = props.Course.parts;
const total = parts.reduce((previousValue, currentValue) => {
return previousValue + currentValue;
}, 0);
Output is shown as:
0[object Object][object Object][object Object][object Object]
return previousValue + currentValue.excercisesshould probably do.Course(capital "C") is not the same ascourse(small "c") for JavaScript.const parts = props.Course.parts;should beconst parts = props.course.parts;. Furthermore, as @WiktorZychla already pointed out, you have to access theexercisesattribute of the current items.