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

131
Vistas
How can I find the sum of of Similar array object values and separate them based on their values

I have the following array object

  [{ 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" }]

I would want to add the objects and get their sums based on the dates. So the result should look something like this

[{
  "2022 07 19" : 10,
  "2022 07 20" : 2
}]
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Just group by the desired property using reduce method.

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 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