I have a message JSON object where for each message there is a timeStamp of when it was submitted. I would like to sort that object based on the timeStamp.
For example:
"Messages": {
"message1": {
"msg" : "I'm trying to make this work",
"timeStamp" : "2018-02-15T06:24:44.12+00:00"
},
"message2": {
"msg" : "I really need your help SO!",
"timeStamp" : "2018-03-01T13:57:27+00:00"
},
"message3": {
"msg" : "Please assist me dude!",
"timeStamp" : "2018-03-01T11:57:27+00:00"
}
}
The timeStamp generated is from momentjs
using moment().format();
.
The issue is, I'm not really sure how to filter an object based on that timestamp format.
I currently have no working example and cant think of a better way.
Why do I need this?
I'm using this object to show messages between two people, but the messages need to be in order based on time.
Can't you just change the format and make it simple?
No because, currently my whole application is based on that format, and changing it will cause more issues.
Update
I've forgotten mention that the format of the output must be an object after sorting (where most recent is first item)