Created
December 14, 2010 10:39
-
-
Save fatgy/740253 to your computer and use it in GitHub Desktop.
Javascript sort Object by value
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
/* | |
http://nemojkliknut.com/blog/javascript-sort-object-by-value/55 | |
a simple bubble sort algorithm on an object | |
*/ | |
function bubbleSortObject(object) { | |
for (i in object) { | |
for (k in object) { | |
if (object[i] < object[k]) { | |
var temp = object[i]; | |
object[i] = object[k]; | |
object[k] = temp; | |
} | |
} | |
} | |
return object; | |
} | |
var numbers = new Object({'item1': 12345, 'item2': 98765, 'item3': 0.00001}); | |
var result = bubbleSortObject(numbers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment