1 |
One can iterate over all properties of an object:
|
2 |
for ( variable in object ) { É }
|
3 |
function dump_props(obj, obj_name) {
|
4 |
var result = "";
|
5 |
for ( var i in obj ) {
-
result +=
-
obj_name + "." + i + " = " + obj[i] + "<BR>";
|
6 |
}
|
7 |
return result + "<HR>";
|
8 |
}
|
9 |
Here i is an index and obj[i] is the actual property
|
10 |
Note user supplies obj and obj_name:
|
11 |
function car(make, model) { // An Example
|
12 |
this.make = make; this.model = model;
|
13 |
}
|
14 |
mycar = new car("Ford", "Explorer");
|
15 |
document.writeln(dump_props(mycar, "mycar"));
|