Enumerating JavaScript Object Properties

I am building a few controls that use client-side script for reuse in the one web app I'm working on. I needed a way to enumerate the property names and values of an object in JavaScript so I knew which properties I had access to. Here's a JavaScript method I put together to enumerate the properties of a CustomValidator object. I have the function name as the value of the ClientValidationFunction:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function myValidator(source, args) 
{
    var property, propCollection = "";

    for(property in source.parentElement)
    {
        propCollection += (property + ": " + source[property] + "\n");
    }
    
    alert(propCollection);

    // For now, show the entry as invalid
    args.IsValid = false;
}

Published Thursday, February 14, 2008 11:29 AM by Jason N. Gaylord

Comments

# Enumerating JavaScript Object Properties « Java Net

Thursday, February 14, 2008 2:29 PM by Enumerating JavaScript Object Properties « Java Net

Pingback from  Enumerating JavaScript Object Properties « Java Net

# Interesting Finds: February 15, 2008

Friday, February 15, 2008 10:02 AM by Jason Haley

# customvalidator not working

Friday, May 16, 2008 4:58 PM by customvalidator not working

Pingback from  customvalidator not working

# re: Enumerating JavaScript Object Properties

Sunday, July 05, 2009 10:34 PM by Devon Sean McCullough

The white-on-white code is hard to read even when selected.

Leave a Comment

(required) 
(required) 
(optional)
(required)