Skip to content

Instantly share code, notes, and snippets.

@Donmclean
Last active April 14, 2017 14:08
Show Gist options
  • Save Donmclean/f9aa00376de2f659c9fe0c1ad90478f8 to your computer and use it in GitHub Desktop.
Save Donmclean/f9aa00376de2f659c9fe0c1ad90478f8 to your computer and use it in GitHub Desktop.
Utilizes reduce method to sort object keys
//Sort obj keys.
//eg: {a: 'test', c: 'test', b: 'test'}
//to: {a: 'test', b: 'test', c: 'test'}
sortObjByOwnKeys = (obj) => Object.keys(obj).sort().reduce((accObj, key) => {
accObj[key] = obj[key];
return accObj;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment