Skip to content
Advertisement

Sorting An Array Of Objects Based On Time And Date

I have an object with the following structure:

JavaScript

I wanted to sort this on the basis of the time and date, and this is what I tried:

JavaScript

but this is returning an error stating:

JavaScript

Advertisement

Answer

The sort() method can only apply applied to array, the provided data is an object.

If you just want the sorted index array

JavaScript

Or if you want to convert it to a sorted array based on the time and date then do something like this,

JavaScript

In case if you want to re-index based the object keys then do something like this using sorted object array

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement