Created
September 10, 2014 00:01
-
-
Save dac09/6985086746dabb083e9a to your computer and use it in GitHub Desktop.
Recursively convert object keys from CapitalCase to camelCase
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 camelCase(input) { | |
return input.charAt(0).toLowerCase() + input.slice(1); | |
} | |
function allCapitalCasetoCamelCase(obj) { | |
var output = {}; | |
for (i in obj) { | |
if ((Object.prototype.toString.apply(obj[i]) === '[object Object]') || (Object.prototype.toString.apply(obj[i]) === '[object Array]') ) { | |
output[camelCase(i)] = allCapitalCasetoCamelCase(obj[i]); | |
} else { | |
output[camelCase(i)] = obj[i]; | |
} | |
} | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment