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

130
Views
¿Cómo puedo encontrar la suma de valores de objetos de matriz similares y separarlos en función de sus valores?

Tengo el siguiente objeto de matriz

 [{ count: 2, created_data: "2022 07 19" }, { count: 4, created_data: "2022 07 19" }, { count: 4, created_data: "2022 07 19" }, { count: 1, created_data: "2022 07 20" }, { count: 1, created_data: "2022 07 20" }]

Me gustaría agregar los objetos y obtener sus sumas según las fechas. Así que el resultado debería ser algo como esto

 [{ "2022 07 19" : 10, "2022 07 20" : 2 }]
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simplemente agrupe por la propiedad deseada usando el método de reduce .

 var data = [{ count: 2, created_data: "2022 07 19" }, { count: 4, created_data: "2022 07 19" }, { count: 4, created_data: "2022 07 19" }, { count: 1, created_data: "2022 07 20" }, { count: 1, created_data: "2022 07 20" }] var result = [data.reduce(function(agg, item) { agg[item.created_data] = (agg[item.created_data] || 0) + item.count return agg }, {})] console.log(result)

about 4 years ago · Santiago Trujillo 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!