#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    158
    Rep Power
    98

    [Solved] Object issues


    Hello all,

    I have an object defined as such:

    JavaScript Code:
     
    var myObject = new Object();


    I'm trying to extend the object to iterate through the properties.

    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:
     
    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:

    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.
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2011
    Posts
    158
    Rep Power
    98
    I was missing the fact that I was trying to edit the data before the JSON call came back...

    Chalk this one up to too many long hours.

IMN logo majestic logo threadwatch logo seochat tools logo