JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 12th, 2013, 11:48 AM
WrinkledCheese's Avatar
WrinkledCheese WrinkledCheese is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 138 WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 16 h 13 m 36 sec
Reputation Power: 96
[Solved] Object issues

Hello all,

I have an object defined as such:

JavaScript Code:
Original - JavaScript Code
  1.  
  2. var myObject = new Object();


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

JavaScript Code:
Original - JavaScript Code
  1.  
  2. for(dynamicProperty in jsonData){
  3.   Object.defineProperty(window.myObject, dynamicProperty, {
  4.     value: {'sub-object-property'   :  jsonData[dynamicProperty]},
  5.     writable: true,
  6.     enumerable: true
  7.   });
  8. }


However, I'm having issues iterating through this object.

JavaScript Code:
Original - JavaScript Code
  1.  
  2. console.log('starting loop');
  3. console.log(window.myObject);
  4. console.log('window.myObject properties')
  5. console.log(Object.getOwnPropertyNames(window.myObject));
  6. console.log(Object.keys(window.myObject));
  7. for (dynamicProperty in Object.keys(window.myObject)){
  8.   console.log(window.myObject[dynamicProperty]);
  9.   console.log(typeof window.myObject[dynamicProperty]);
  10. }


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.

Reply With Quote
  #2  
Old March 13th, 2013, 09:41 AM
WrinkledCheese's Avatar
WrinkledCheese WrinkledCheese is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2011
Posts: 138 WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level)WrinkledCheese User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Day 16 h 13 m 36 sec
Reputation Power: 96
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > [Solved] Object issues

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap