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

206
Views
encuentre un valor similar de un objeto de matriz y calcule el vendido

Hola, estoy tratando de encontrar un valor similar de este objeto de matriz y calcular algunos de los vendidos para cada uno de los mismos valores.

 const sold = [ { matri: 1, year: 2019, sold: 5 }, { matri: 2, year: 2020, sold: 3 }, { matri: 1, year: 2020, sold: 7 }, ];

arriba tengo un objeto de matriz el resultado esperado

 { matri: 1, year: 2020, sold: 5 }, { matri: 1, year: 2020, sold: 7 },

vendido: 5 + vendido: 7

producción vendida : 12

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

0

Puede usar reduce para agrupar y sumar la propiedad sold :

 const sold = [ { matri: 1, year: 2019, sold: 5 }, { matri: 2, year: 2020, sold: 3 }, { matri: 1, year: 2020, sold: 7 }, ]; const result = Object.values(sold.reduce((carry, entry) => { if (!carry.hasOwnProperty(entry.matri)) { carry[entry.matri] = {matri: entry.matri, sold: entry.sold}; } else { carry[entry.matri].sold += entry.sold; } return carry; }, {})); console.log(result);

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!