我最近張貼了這個問題的PHP,但現在我希望它爲JavaScript我要排序3維數組在javascript
我的陣列是以下幾點:
var inboxMessages = {
105775: { //index is thread_id
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: { //index is thread_id
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: { //index is thread_id
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: { //index is thread_id
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,
}
}
};
所以現在我需要輸出像這樣:
var inboxMessages = {
378552: {//index is thread_id
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: {//index is thread_id
0: {
'id': 88,
'thread_id': 224199,
'message': "yessss...",
'created_at': "May 20, 2015",
'datetime': 1432306513,
'sender_id': 14,
},
1: {//index is thread_id
'id': 75,
'thread_id': 224199,
'message': "hellowwww...",
'created_at': "May 19, 2015",
'datetime': 1432021227,
'sender_id': 14,
}
},
105775: {//index is thread_id
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: {//index is thread_id
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,
}
},
};
我不知道該如何排序這在JS中。
我需要近期線程的陣列的datetime
是陣列
這根本不是一個數組,更不用說一個3D - 它只是一個對象,對象的屬性沒有對它們的順序。 – dave
我們不是代碼翻譯服務... –
你不能那樣做... JavaScript對象是無序的。 – tymeJV