I have an array of objects. I want to sort the array according to the object key. For example below -
{
"id": 3511,
"time": "03:30",
"hour": 3,
"utc_date_time": "2020-07-07T02:07:54.000Z",
"members": 0
},
{
"id": 3514,
"time": "04:30",
"hour": 4,
"utc_date_time": "2020-07-07T02:07:54.000Z",
"members": 0
},
{
"id": 3513,
"time": "04:00",
"hour": 4,
"utc_date_time": "2020-07-07T02:07:54.000Z",
"members": 0
},
I want to sort it according to time like this-
{
"id": 3511,
"time": "03:30",
"hour": 3,
"utc_date_time": "2020-07-07T02:07:54.000Z",
"members": 0
},
{
"id": 3513,
"time": "04:00",
"hour": 4,
"utc_date_time": "2020-07-07T02:07:54.000Z",
"members": 0
},
{
"id": 3514,
"time": "04:30",
"hour": 4,
"utc_date_time": "2020-07-07T02:07:54.000Z",
"members": 0
},
I have used this function to sort but it is not giving the expected output I have also used the time key, still the same.
timeSlots.sort(function(a, b) {
return a.time- b.time;
});
But not getting an expected output.