Skip to content

Instantly share code, notes, and snippets.

@robrighter
Created March 11, 2011 21:52
Show Gist options
  • Save robrighter/866644 to your computer and use it in GitHub Desktop.
Save robrighter/866644 to your computer and use it in GitHub Desktop.
Turn a javascript object into an array sorted by the object keys
function makeSortedObject(obj, casesensitive){
return Object.keys(obj).map(function(key){
return {key: key, value: obj[key]};
}).sort(function(a,b){
return (casesensitive? a.key : a.key.toLowerCase()) > (casesensitive? b.key : b.key.toLowerCase());
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment