Skip to content

Instantly share code, notes, and snippets.

@vvo
Last active August 29, 2015 14:08
Show Gist options
  • Select an option

  • Save vvo/44b02018504db10c7f7a to your computer and use it in GitHub Desktop.

Select an option

Save vvo/44b02018504db10c7f7a to your computer and use it in GitHub Desktop.
deeply remove "private _properties" of JavaScript objects
function removePrivateProperties(dirty) {
return Object.keys(dirty).reduce(function(clean, keyName) {
if (keyName.indexOf('_') === 0) {
return clean;
}
var value = dirty[keyName];
if (typeof value === 'object' && Object.keys(value).length > 0) {
value = removePrivateProperties(value);
}
clean[keyName] = value;
return clean;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment