How to list all properties from any object without of using "Developer tools"
Not always we have the possibility to open "Developer tools" on personal computer. Now, in 2024 a lot of developers programs direct on smartphones and on smartphon we do not have "Developer tools" like on PC.
But even on smartphon you can inspect each object and can see all properties from objects.
For this case we can use for in
loop:
The for...in
statement iterates over all enumerable string properties of an object (ignoring properties keyed by symbols), including inherited enumerable properties.
We can use it like follows:
for(var property in anyObject)
console.log(property + ': ' + anyObject[property]);
So, for example if you want to see event.target
properties then you could do it like follows:
function writeProperties()
{
var str = '';
for (var i in event.target)
str += '<b style="color:green">' + i + '</b>: ' + event.target[i] + '<hr>';
document.querySelector('#output').innerHTML = str;
}
<button onclick="writeProperties()">Write all properties from event.target</button>
<div id="output"></div>
After starting of this snippet above you will see the button and after clicking of the button you will see all properties from this button object because in event.target
will be this button object.
But instead of event.target
you could take even window
or document
objects and ispect them. You could write your own "Insperter App" in normal JavaScript without of using from "Developer tools". Try it!