Hi I am trying to sum the value of total_msg_send of these objects, the first sum is good but in the rest of them it sums the previous result with the result of the next sum
This is the code that I have
this.groups = rsp['cards'];
for (let index = 0; index < Object.keys(this.groups).length; index++) {
const element = this.groups[index];
this.apiSvc.receiveMessages(element.id).subscribe((rsp: any) =>{
console.log(rsp); //object
rsp.forEach(element => {
this.sum += parseInt(element.total_msg_send);
});
console.log(this.sum);//sum
});
}
I'll appreciate if someone can help me, thanks