Just the other day, I posted a question on PHP, but now I need similar help for JavaScript.
Here is my array :
var inboxMessages = {
105775: {
0: {
'id': 85,
'thread_id': 105775,
'message': "hello",
'created_at': "May 20, 2015",
'datetime': 1432118191,
'sender_id': 13,
},
1: {
'id': 70,
'thread_id': 105775,
'message': "hii",
'created_at': "May 19, 2015",
'datetime': 1432021227,
'sender_id': 13,
}
},
224199: {
0: {
'id': 88,
'thread_id': 224199,
'message': "yessss...",
'created_at': "May 20, 2015",
'datetime': 1432306513,
'sender_id': 14,
},
1: {
'id': 75,
'thread_id': 224199,
'message': "hellowwww...",
'created_at': "May 19, 2015",
'datetime': 1432021227,
'sender_id': 14,
}
},
107917: {
0: {
'id': 56,
'thread_id': 107917,
'message': "how r u??",
'created_at': "May 16, 2015",
'datetime': 1431792155,
'sender_id': 14,
},
1: {
'id': 30,
'thread_id': 107917,
'message': "hi.. i m fine.",
'created_at': "May 6, 2015",
'datetime': 1430920006,
'sender_id': 14,
},
2: {
'id': 30,
'thread_id': 107917,
'message': "hi!!!!..how r u??",
'created_at': "May 6, 2015",
'datetime': 1430920006,
'sender_id': 14,
}
},
378552: {
0: {
'id': 108,
'thread_id': 378552,
'message': "hi",
'created_at': "May 29, 2015",
'datetime': 1432906923,
'sender_id': 14,
},
1: {
'id': 107,
'thread_id': 378552,
'message': "hi.",
'created_at': "May 29, 2015",
'datetime': 1432903194,
'sender_id': 14,
}
}
};
Now, I need the output to be like this :
var inboxMessages = {
378552: {
0: {
'id': 108,
'thread_id': 378552,
'message': "hi",
'created_at': "May 29, 2015",
'datetime': 1432906923,
'sender_id': 14,
},
1: {
'id': 107,
'thread_id': 378552,
'message': "hi.",
'created_at': "May 29, 2015",
'datetime': 1432903194,
'sender_id': 14,
}
},
224199: {
0: {
'id': 88,
'thread_id': 224199,
'message': "yessss...",
'created_at': "May 20, 2015",
'datetime': 1432306513,
'sender_id': 14,
},
1: {
'id': 75,
'thread_id': 224199,
'message': "hellowwww...",
'created_at': "May 19, 2015",
'datetime': 1432021227,
'sender_id': 14,
}
},
105775: {
0: {
'id': 85,
'thread_id': 105775,
'message': "hello",
'created_at': "May 20, 2015",
'datetime': 1432118191,
'sender_id': 13,
},
1: {
'id': 70,
'thread_id': 105775,
'message': "hii",
'created_at': "May 19, 2015",
'datetime': 1432021227,
'sender_id': 13,
}
},
107917: {
0: {
'id': 56,
'thread_id': 107917,
'message': "how r u??",
'created_at': "May 16, 2015",
'datetime': 1431792155,
'sender_id': 14,
},
1: {
'id': 30,
'thread_id': 107917,
'message': "hi.. i m fine.",
'created_at': "May 6, 2015",
'datetime': 1430920006,
'sender_id': 14,
},
2: {
'id': 30,
'thread_id': 107917,
'message': "hi!!!!..how r u??",
'created_at': "May 6, 2015",
'datetime': 1430920006,
'sender_id': 14,
}
},
};
I'm not sure how to sort this in JS.
I want the most recent datetime
for each thread to be at the top of the array.