Skip to content
Advertisement

Sorting date by date and month excluding an year in typescript [closed]

I need to sort an array having date and month as input.

ex: date = [“01-jun”,”2-may”,”23-apr”,”10-dec”];

Advertisement

Answer

You can try it :

let date = ["01-jun","2-may","23-apr","10-dec"]
date.sort((a, b) => {
  let dateA = new Date(a)
  let dateB = new Date(b)
  return dateA - dateB
})
console.log(date)
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement