How to Get or List All Properties and its Value from JavaScript Object?
We can access a property value of a javscript object using obj[propertyName] syntax. Thus, we need to know the property name of the javascript object before actually accessing it.
But, it is very hard to find all the available properties of a javascript object which is predefined or which does not have supporting documentation in order to use it.
The below little code snippet will help us to get all the available properties and its value from the javascript object.
for (var propertyName in evt) { alert("evt[" + propertyName + "]: " + evt[propertyName]); }
The above script will enumerate all the property name in the evt javascript object and will alert the property name with its value.
Happy Coding!!
|