Skip to content

Instantly share code, notes, and snippets.

@ngryman
Created March 7, 2013 22:22
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 ngryman/5112364 to your computer and use it in GitHub Desktop.
Save ngryman/5112364 to your computer and use it in GitHub Desktop.
camel case sanitizing
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