Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
sum values of an object independent from the previous array

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

results

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

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the reduce function on the array

const reducer = (acc, value) => acc + parseInt(value.total_msg_send);
const sum = rsp.reduce(reducer, 0);
console.log(sum);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!