Skip to content

Instantly share code, notes, and snippets.

@maxgherman
Last active August 29, 2015 14:16
Show Gist options
  • Save maxgherman/329b583a4db00ef5f736 to your computer and use it in GitHub Desktop.
Save maxgherman/329b583a4db00ef5f736 to your computer and use it in GitHub Desktop.
Retrieve all property names for JavaScript object including non enumerables
function getAllPropertyNames(obj) {
var props = {};
do {
Object.getOwnPropertyNames(obj).forEach(function (prop) {
if (prop !== 'constructor') {
props[prop] = undefined;
}
});
} while ((obj = Object.getPrototypeOf(obj)) !== Object.prototype);
return Object.getOwnPropertyNames(props);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment