Created
March 7, 2013 22:22
-
-
Save ngryman/5112364 to your computer and use it in GitHub Desktop.
camel case sanitizing
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 sanitize(obj) { | |
if ($.isArray(obj)) { | |
for (var i = 0, len = obj.length; i < len; i++) { | |
obj[i] = sanitize(obj[i]); | |
} | |
} | |
else { | |
for (var p in obj) { | |
if (!obj.hasOwnProperty(p)) continue; | |
if ('object' == typeof obj[p]) { | |
obj[p] = sanitize(obj[p]); | |
} | |
obj[p.charAt(0).toLowerCase() + p.slice(1)] = obj[p]; | |
delete obj[p]; | |
} | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment