Utilizing for
-in
loops allows for iteration through each property within an object or array, giving access to both the value and the ability to modify it.
Note: Private properties remain inaccessible for inspection unless a "spy" is employed; essentially, one must override the object and implement code that performs a for-in loop within the object's context.
The syntax of a for-in loop is as follows:
for (var property in object) loop();
An example snippet of such a loop in action:
function xinspect(o,i){
if(typeof i=='undefined')i='';
if(i.length>50)return '[MAX ITERATIONS]';
var r=[];
for(var p in o){
var t=typeof o[p];
r.push(i+'"'+p+'" ('+t+') => '+(t=='object' ? 'object:'+xinspect(o[p],i+' ') : o[p]+''));
}
return r.join(i+'\n');
}
// example of use:
alert(xinspect(document));
Edit: Previously, I developed my own inspector tool. If you're interested, I'd be happy to share it with you.
Edit 2: As a matter of fact, I went ahead and created one regardless.