Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda