Check the properties

Sometimes we have an object and the object is valid, but the property we are trying to check is not. We could do an alert for every property, but this could be time consuming. Sometimes a simple list of properties and their values is what we need. You can do this with a quick routine:

var output = "";
for (var prop in myObject) {
output = output + prop + "; " + myObject[prop] + "\n";
}
alert(output);

This code is taking advantage of the way JavaScript treats properties. We'll just trust this will work for now (the technique is explained elsewhere in the HowTo's). If we ran this against a custom "person" object, this code might result in the following message:

name: "Bob Smith"
phone: "(555) 555-5555"
address: "123 Main Street"

If we were looking for a "birthday" property, we can very quickly see that there is no such property.

This technique is a longer form of checking for the existence of an object or property, but is useful when you need a greater understanding of what is happening with your data or code.