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

213
Views
¿Cómo sumar valores de multiplicación de objetos en una matriz?

si tengo una matriz que se ve así:

 "orderItems": [ { "description": "Test", "identifier": "Test identifier", "priceCent": 1, "lengthIn": 10, "widthIn": 5, "heightIn": 10, "weightLbs": 3, "quantity": 2 }, { "description": "Test-2", "identifier": "Test identifier", "priceCent": 1, "lengthIn": 10, "widthIn": 5, "heightIn": 10, "weightLbs": 4, "quantity": 3 } ]

¿Cómo puedo multiplicar las libras de peso y la cantidad y sumarlas dentro de los objetos? Por ejemplo:

3 * 2 = 6 4 * 3 = 12

y el resultado total que quiero es = 18

Esto es lo que tengo hasta ahora, pero esto solo agrega pesoLbs

 return delivery.order.orderItems.reduce((prev, curr) => { return prev + (curr.totalWeightLbs || 0); }, 0);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

orderItems.reduce((sum, currentItem) => { return sum + (currentItem.weightLbs * currentItem.quantity); }, 0);

esto multiplicará los valores y los sumará en el acumulador de reduce

about 4 years ago · Juan Pablo Isaza Report

0

 const dummyArray = [ { "description": "Test", "identifier": "Test identifier", "priceCent": 1, "lengthIn": 10, "widthIn": 5, "heightIn": 10, "weightLbs": 3, "quantity": 2 }, { "description": "Test-2", "identifier": "Test identifier", "priceCent": 1, "lengthIn": 10, "widthIn": 5, "heightIn": 10, "weightLbs": 4, "quantity": 3 } ]; let sum = 0; for( i = 0; i < dummyArray.length; i++) sum += dummyArray[i].weightLbs * dummyArray[i].quantity console.log(sum)

esto podría funcionar

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!