const activityDetails = [
{
username: "Tester",
pointDetails: [
{
points: 4826,
pointType: "BONUS"
},
{
points: 9652,
pointType: "BASE"
},
{
points: 14478,
pointType: "CLS"
}
]
},
{
username: "Tester2",
pointDetails: [
{
points: 1126,
pointType: "BONUS"
},
{
points: 9652,
pointType: "BASE"
},
{
points: 44566,
pointType: "CLS"
}
]
}
]
Ниже приведен код, который я пытаюсь перебрать в массиве и подсчитать точку BONUS и BASE. Я что-то упустил или есть лучший способ перебрать массив и подсчитать число? спасибо
activityDetails.filter(n=>{
n.pointDetails.reduce((sum:any, rates:any) => {
if (rates.pointType === "BONUS" || rates.pointType === "BASE") {
sum+= rates.points;
console.log(sum);
}
}, 0)
})