Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda