Skip to content

Instantly share code, notes, and snippets.

@gobwas
Created November 14, 2014 11:31
Show Gist options
  • Save gobwas/fff42490c4a507441779 to your computer and use it in GitHub Desktop.
Save gobwas/fff42490c4a507441779 to your computer and use it in GitHub Desktop.
{
flatten: function(obj) {
function flatten(obj) {
return _.reduce(obj, function(memo, value, key) {
if (_.isObject(value)) {
_.forEach(flatten(value), function(v, k) {
memo[key + "." + k] = v;
});
} else {
memo[key] = value;
}
return memo;
}, {})
}
return flatten(obj);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment