Display the properties from an object one by one : Objects Object Oriented « Language Basics « JavaScript DHTML






Display the properties from an object one by one

 

<head>
<title></title>
</script>
</head>
<body>
<script type = "text/javascript" >
    function MyClass(a,b,c,d) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
    }

    var MyClass = {};

    MyClass["item1"] = new MyClass("A","B","F",2.0);

for (var propt in MyClass) {
    document.write( propt );
    document.write("<BR>");
}


var names = new Array;
for (propt in MyClass) {
    if (names != "") {
        names += "," + propt;
    } else {
        names = propt;
    }
}
document.write(names);

</script>
<p>MyClasss</p>
</body>

   
  








Related examples in the same category

1.Object utility: create, parse and profile
2.Define Object, use its instance
3.Define and use object
4. Creating an Object and Using Object Instance Properties and Methods
5. Object-Oriented Planetary Data Presentation
6.The Book Object Definition
7.Complete Example of Using the employee, client, and project Objects
8.Source Code for the showBook() Example
9.Using the Book Object Constructor
10.Creating Objects Dynamically
11.Object to array
12.Utility class for JavaScript class definition
13.Create an object and add attributes
14.Use for in loop to display all attributes from an object
15.An object and its constructor
16.Use function as the object constructor