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

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