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

188
Visualizações
How to sort the date array of objects in JS?

I am trying to make the normalized date object. Right now I have

  const data = [{
    createdDate: '2019-01-06T14:39:33.564Z',
  },
  {
    createdDate: '2018-01-07T14:39:33.564Z',
  },
  {
    createdDate: '2018-01-07T14:39:33.564Z',
  },
  {
    createdDate: '2019-01-06T14:39:33.564Z',
  }]

this is the record of when the user is registered on the system. So according to the following i need to make the number of users by year, by month of that year, by week of the selected month of the year I need to sort this array into something like:

const updatedData = [
  <year>: [
    <month>: [
      <week number>: {
        count: <number of users registered>
      }
    ]
  ]
]

So far I tried to make it in this way, but something is missing and cannot figure out what is and how to make it. Please can you explain it, would really appreciate it?

const data = [{
    createdDate: '2019-01-06T14:39:33.564Z',
  },
  {
    createdDate: '2018-01-07T14:39:33.564Z',
  },
  {
    createdDate: '2018-01-07T14:39:33.564Z',
  },
  {
    createdDate: '2019-01-06T14:39:33.564Z',
  }
]

const updateData = data.map((item, index) => {
  const date = new Date(item.createdDate);
  const year = date.getFullYear();
  const month = date.toLocaleDateString('default', {
    month: '2-digit'
  });
  return {
    [year]: [{
      [month]: {
        userCount: index,
      },
    }, ],
  };
});
console.log(updateData)

about 4 years ago · Juan Pablo Isaza
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