Apologies if the title was a bit unclear. Let me try to elaborate on the question: I have an array with some sample data as shown below:
const data = [
{
name: "Bob",
items: [1]
},
{
name: "charlie",
items: [1,2]
},
{
name: "Chris",
items: [5]
}
]
I've organized the items in arrays because there can be more than one item sometimes. Now, my question is how can I calculate the sum of all these items, which should equal 4? (the first array has 1 element, the second array has 2 elements, and the last one has 1 element) I've been struggling with this and tried using map and reduce functions, but it hasn't worked as expected... Appreciate any insights or solutions you guys might have. Thank you!