Skip to content

Instantly share code, notes, and snippets.

@piscis
Created March 6, 2012 14:56
Show Gist options
  • Save piscis/1986678 to your computer and use it in GitHub Desktop.
Save piscis/1986678 to your computer and use it in GitHub Desktop.
JSON Sort
function sortObject(o) {
var sorted = {},
key, a = [];
for (key in o) {
if (o.hasOwnProperty(key)) {
a.push(key);
}
}
a.sort(function(g,h){
return (g - h);
});
for (key = 0; key < a.length; key++) {
sorted[a[key]] = o[a[key]];
}
return sorted;
}
var a = {25:0.5, 8:0.6, 7:0.123};
sortObject(a);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment