I want to create an object array that contains all the dates from each object sorted in order from the most recent date to the oldest date.
How can I loop through the dates for each object and sort them?
Will medList[0].data.sort
work?
I want to sort it like this:
var newArray = [{"dose": 10, "date": "2/15/2020"}, {"dose": 20, "date": "1/18/2020"}, {"dose": 20, "date": "12/21/2019"}]
const medList = [
{
"name": "Insulin",
"dose unit": "mg",
"freq": "daily",
"route": "PO",
"data": [
{
"dose": 20,
"date": "12/21/2019"
},
{
"dose": 10,
"date": "2/15/2020"
}, {
"dose": 20,
"date": "1/18/2020"
}
]
},
{
// Another med...
} ..
]