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)