Created
January 13, 2021 08:26
-
-
Save tranchausky/789bef19574adba358b7b74b1e2a328e to your computer and use it in GitHub Desktop.
Sort firebase data in descending
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sortDescObj(list, key) { | |
| var sortedKeys = Object.keys(list).sort(function(a,b) { | |
| return list[a][key] > list[b][key] ? -1:1 | |
| }); | |
| var newObjectSort = [] | |
| var tem=[] | |
| for (let index = 0; index < sortedKeys.length; index++) { | |
| tem=[] | |
| newObjectSort.push(list[sortedKeys[index]]) | |
| } | |
| return newObjectSort | |
| } | |
| //time: new Date().getTime(), | |
| //firebase test get result sort time | |
| contactsRef.orderByChild('time').on("value", function(snapshot) { | |
| allContacts = snapshot.val() | |
| var newObjectSort = sortDescObj(allContacts,'time') | |
| showContentContact(newObjectSort) | |
| }, function(errorObject) { | |
| console.log("The read failed: " + errorObject.code); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment