Last active
February 8, 2018 08:37
-
-
Save SnitchRUS66/5167e8789a2fe075fbe78ded84e38edf to your computer and use it in GitHub Desktop.
sort js obj props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortObjectProps(o) { | |
var sorted = {}, | |
key, a = []; | |
for (key in o) { | |
if (o.hasOwnProperty(key)) { | |
a.push(key); | |
} | |
} | |
a.sort(); | |
for (key = 0; key < a.length; key++) { | |
sorted[a[key]] = o[a[key]]; | |
} | |
return sorted; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment