Reputation: 227
I would like to be able to iterate through all the members of an object. something like this:
function reflect(obj) {
var str = "";
for (member in obj) { str += (member + "\n"); }
return str;
}
but the Enumerable flag prevents many of the members to apear in the for in loop. my question is:
is there another way to iterate through an object's members that exposes all of them?
if not, is there some access to these flags? (can I set Enumerable to true?)
is there a way to expose the prototype chain and determine which member belongs to which ancestor?
Upvotes: 2
Views: 54
Reputation: 9975
You can use getOwnPropertyNames
for that. It returns all properties regardless of the enumerable option.
var objectProperties = Object.getOwnPropertyNames(obj);
Update This is only available for Javascript 1.8.5 and newer! (thanks @Kiyura)
Upvotes: 1