0

{"id":"365","month":"December","date":"30","sehri":"05:40 AM","fajr":"05:46 AM","tulu_e_aaftab":"07:06 AM","makrooh":"11:49 AM","zohar":"12:30 PM","asar":"04:18 PM","magrib":"05:53 PM","isha":"07:13 PM"},{"id":"366","month":"December","date":"31","sehri":"05:40 AM","fajr":"05:46 AM","tulu_e_aaftab":"07:06 AM","makrooh":"11:49 AM","zohar":"12:30 PM","asar":"04:19 PM","magrib":"05:53 PM","isha":"07:13 PM"}

this is json i need output like this enter image description here

1 Answers1

0

Given your objects contain multiple datapoints about the date they represent, I recommend using a Date() object to store this information. That way you would be able to sort the array simply like this:

const sortedDates = arrayOfDateObjects.sort((a, b) => b.date - a.date)

Likewise if you wanted to preserve your object format, you can use the Date object only within the sort function:

const sortedDates = originalArray.sort((a, b) => {
    let dateA = new Date();
    // extract the date from a and apply it to dateA
    let dateB = new Date();
    // extract the date from b and apply it to dateB
    return dateA - dateB
});

You can find out more information about the Date object here

Ben Werner
  • 44
  • 5