Skip to content

Instantly share code, notes, and snippets.

@kristerkari
Created September 19, 2013 20:45
Show Gist options
  • Save kristerkari/6629600 to your computer and use it in GitHub Desktop.
Save kristerkari/6629600 to your computer and use it in GitHub Desktop.
function sortByKey(obj) {
var newObj = {};
Object.keys(obj).sort().forEach(function(key) {
newObj[key] = obj[key];
});
return newObj;
}
var obj = {
b: 2,
a: 1,
c: 3
};
sortByKey(obj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment