Skip to content

Instantly share code, notes, and snippets.

@lski
Created March 29, 2020 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lski/a2e89c06f1fb29ef121cf48d6aa2a2ca to your computer and use it in GitHub Desktop.
Save lski/a2e89c06f1fb29ef121cf48d6aa2a2ca to your computer and use it in GitHub Desktop.
Sort Object Properties
/**
* Does a simple (single level) sort on the properties in an object.
* @returns {Map}
*/
function sortObjectProps(json) {
return Object.keys(json)
.sort((a, b) => a >= b)
.reduce((accumulator, item) => {
accumulator.set(item, json[item]);
return accumulator;
}, new Map());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment