Skip to content

Commit 6d259b4

Browse files
hemanthgnarf
authored andcommitted
js101/objects: Iterating properties of an Object.
Closes jquerygh-371
1 parent dd6c3bb commit 6d259b4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

page/javascript-101/objects.md

+23
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,26 @@ var myObject = {
3333
99999: 789
3434
};
3535
```
36+
## Iterating Over the Enumerable Properties of an Object:
37+
38+
```
39+
var myObject = {
40+
validIdentifier: 123,
41+
"some string": 456,
42+
99999: 789
43+
};
44+
45+
for ( var prop in myObject ) {
46+
// Determine if the property is on the object itself.
47+
// (not on the prototype)
48+
if ( myObject.hasOwnProperty( prop ) ) {
49+
console.log( "Property : " + prop + " ; value : " + myObject[ prop ] );
50+
}
51+
}
52+
53+
// Would log the following:
54+
// Please that the order is not guaranteed and may differ.
55+
56+
// Property : 99999 ; value : 789
57+
// Property : validIdentifier ; value : 123
58+
// Property : some string ; value : 456

0 commit comments

Comments
 (0)