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

186
Views
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
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!