Created
March 11, 2011 21:52
-
-
Save robrighter/866644 to your computer and use it in GitHub Desktop.
Turn a javascript object into an array sorted by the object keys
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 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