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

116
Views
Convert string in Array to date and sort in descending order

I have an array with objects and each contain date in the format : day ' month ' year

Here is the example of single object in that array

{
    "title": "“All’Improvviso” - Cajo Fabricio",
    "artist": "Johann Adolf Hasse",
    "link": "https://www.facebook.com/AllimprovvisoFestivalGliwice",
    "day": "sobota, godz. 18:00",
    **"date": "26 ' 06 ' 2021",**
    "place": "Ruiny Teatru Victoria",
    "city": "Gliwice",
    "canceled": false,
    "ticketSoon": false
}

I want to create a new array from this objects with the descending order of a date.

Can anyone help? I am making the calculations in Nuxt project

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parse the string as date and then sort the array in order of date

const data = [{
  "artist": "Johann Adolf Hasse",
  "date": "26 ' 06 ' 2021",
}, {
  "artist": "Test Hasse",
  "date": "23 ' 06 ' 2021",

}];

const sortedData = data.map(item => {
  const splitDate = item.date.split("'");
  const newDate = new Date(splitDate[2].trim(), splitDate[1].trim(), splitDate[0].trim());
  return { ...item,
    date: newDate
  }
}).sort((a, b) => {
  return new Date(a.date) - new Date(b.date)

})
console.log(sortedData)

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