Here I'm trying to add number of array separately, but I'm not able to achieve the expected output. If I want to add total I would do flatMap and add them togeather. But I want add them separately for each array.
Below is the snippet for what I have tried
const data = [{
"itemDetails": [{
"sizeOfBag": 1,
"numberOfBags": 1,
"quantityInBag": 1.0
}]
},
{
"itemDetails": [{
"sizeOfBag": 1,
"numberOfBags": 1,
"quantityInBag": 1.0
},
{
"sizeOfBag": 10,
"numberOfBags": 1,
"quantityInBag": 1.0
}
],
}
]
const newData = data.map(f => f.itemDetails);
console.log(newData);
for (let i = 0; i <= newData.length; i++) {
const addData = newData.reduce((acc, newData) => acc + newData[i].sizeOfBag, 0);
}
console.log(addData);
Expected Output: [1,11]
forloop syntax wrong, it should be;between the parts of the header, not,.