Skip to content

Instantly share code, notes, and snippets.

@Yonet
Created May 15, 2015 06:28
Show Gist options
  • Save Yonet/4b6eacbdba8bf3b35fea to your computer and use it in GitHub Desktop.
Save Yonet/4b6eacbdba8bf3b35fea to your computer and use it in GitHub Desktop.
var flatten = function(obj, cKey, returnObj) {
result = returnObj || {};
for(var key in obj) {
var newKey = cKey ? cKey + '.'+ key : key;
if(!(obj[key] instanceof Object)) {
result[newKey] = obj[key];
}
else if (obj[key] instanceof Object){
flatten(obj[key], newKey, result);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment