Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

199
Visualizações
How to sum amount based on the occurrences of repeated dates in an array of objects in JavaScript?

I have this array

const data =[
             {total: 90, date:"2021-11-16T07:20:23.000Z"},
             {total: 10, date:"2021-11-16T07:20:23.000Z"},
             {total: 50, date:"2021-11-17T07:20:23.000Z"}
            ];

i want to sort this array so the objects that have same date i want to sum the values of the total and the number of these objects with same date with new property called count. result should looks like

const newData =[
                { total: 100, date:"2021-11-16T07:20:23.000Z", count:2},
                { total: 50, date:"2021-11-17T07:20:23.000Z", count:1}
              ];
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Start with getting an array of unique date occurence with the help of ...new Set(), then loop through those and when looping filter the original array and map the values.

As others have suggested, nobody here will provide you with the complete code, but at least now you have an idea of how to start.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda