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

113
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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