
March 12th, 2013, 11:48 AM
|
 |
Contributing User
|
|
|
|
|
[Solved] Object issues
Hello all,
I have an object defined as such:
JavaScript Code:
Original
- JavaScript Code |
|
|
|
var myObject = new Object();
I'm trying to extend the object to iterate through the properties.
JavaScript Code:
Original
- JavaScript Code |
|
|
|
for(dynamicProperty in jsonData){ Object.defineProperty(window.myObject, dynamicProperty, { value: {'sub-object-property' : jsonData[dynamicProperty]}, writable: true, enumerable: true }); }
However, I'm having issues iterating through this object.
JavaScript Code:
Original
- JavaScript Code |
|
|
|
console.log('starting loop'); console.log(window.myObject); console.log('window.myObject properties') console.log(Object.getOwnPropertyNames(window.myObject)); console.log(Object.keys(window.myObject)); for (dynamicProperty in Object.keys(window.myObject)){ console.log(window.myObject[dynamicProperty]); console.log(typeof window.myObject[dynamicProperty]); }
Gives the following output in the console:
Quote: | Originally Posted by Console Log
starting loop
Object {} //enumerated as expected
window.countries properties
[] //There are no child objects
[] //There are no child objects
|
I have no idea what I'm missing.
|