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

109
Visualizações
how to sum values ​of arrays in the same position

I have this line of code, how could I add the // "0[37][16]" to total 53 for example?

updateTotalMedidas() {
    this.ɵcart.medidaTotal = 0;
    for (const item of this.ɵcart.item) {
      let row_cm = (item.medidas[0] * item.medidas[1] * item.medidas[2]) * item.quantidade; // (3) [84, 40, 15] and (3) [30, 18, 8]
      let totalCmCubico = row_cm  // 50400 and 4320
      let raiz_cubica =  Math.round(Math.cbrt(totalCmCubico))  // 37 and  16
      this.ɵcart.medidaTotal += JSON.stringify([raiz_cubica]); // "0[37][16]"

    }
  }

if I remove the "[]" from this.ɵcart.medidaTotal it becomes 3716, so I put the [], but I don't understand why it stays in that format

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This happens because you put everything inside JSON.stringify this converts objects into JSON strings. So in your current code mediaTotal will be first 0 then "37" and at last "3716". No need for that in your code.

You can just do this, because raiz_cubica is a number.

this.ɵcart.medidaTotal += raiz_cubica;
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