Skip to content

Instantly share code, notes, and snippets.

@saeidzebardast
Created January 4, 2017 07:28
Show Gist options
  • Save saeidzebardast/7487bb43a541bb820eee55a2cd29955f to your computer and use it in GitHub Desktop.
Save saeidzebardast/7487bb43a541bb820eee55a2cd29955f to your computer and use it in GitHub Desktop.
Sort object by key
/**
* Sort object by key
*
* @param unordered object
* @returns {Object} ordered object by key
*/
function sortObject(unordered) {
var ordered = {};
Object.keys(unordered).sort().forEach(function (key) {
ordered[key] = unordered[key];
});
return ordered;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment