Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function orderKeysAlphabetically(obj) {
- const sortedKeys = Object.keys(obj).sort(function (val1, val2) {
- // val1 = val1.charAt(0);
- // val2 = val2.charAt(0);
- if(val1 > val2) {
- return 1;
- }
- if(val2 > val1) {
- return -1;
- }
- return 0;
- });
- const newObj = {};
- for(let i = 0; i < sortedKeys.length; i ++) {
- newObj[sortedKeys[i]] = obj[sortedKeys[i]];
- }
- return newObj;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement