Skip to content

Instantly share code, notes, and snippets.

@NV
Created May 30, 2011 07:11
Show Gist options
  • Save NV/998546 to your computer and use it in GitHub Desktop.
Save NV/998546 to your computer and use it in GitHub Desktop.
How can I get all keys of an object (including enumerable:false)?
var obj = {};
Object.defineProperty(obj, "x", {value: 42, enumerable: false});
Object.defineProperty(obj.__proto__, "y", {value: 63, enumerable: false});
for (var key in obj) console.log(key)
// nothing
Object.keys(obj)
// []
Object.getOwnPropertyNames(obj)
// ["x"]
@DmitrySoshnikov
Copy link

Object.getOwnPropertyNames

P.S. In addition see my Object.forAll enumeration method: https://gist.github.com/367080/

Dmitry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment