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 August 26th, 2008, 11:48 AM
shawazi shawazi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 123 shawazi User rank is Private First Class (20 - 50 Reputation Level)shawazi User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 9 m 51 sec
Reputation Power: 10
Trouble with associative array

Why wouldn't I be able to get the value of Control.subsriptions in the first case, but am in the second?
Code:
Control.subscriptions = new Array();
Control.subscriptions["abc"] = 'what?';
Control.subscriptions["Def"] = 'is next?';
alert(Control.subscriptions); //alerts blank
alert(Control.subscriptions["abc"]); //alerts "what?"


Code:
Control.subscriptions = new Array();
Control.subscriptions[0] = 'what?';
Control.subscriptions[1] = 'is next?';
alert(Control.subscriptions); //alerts "what?, is next?"
alert(Control.subscriptions[0]); //alerts "what?"


I need to be able to see them to make sure I have cleared all objects later on
__________________
Catch-22

Reply With Quote
  #2  
Old August 26th, 2008, 12:02 PM
URackEm's Avatar
URackEm URackEm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: San Francisco, CA
Posts: 78 URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 2 h 1 m
Reputation Power: 8
Send a message via Google Talk to URackEm
I believe it is because you can't increment associative arrays. Because the values are strings instead of a numerical index. So since you didn't call a specific index or set of indeces, it doesn't know what to return.

At least that is the way I understand it... hopefully I am not way off base.

Reply With Quote
  #3  
Old August 26th, 2008, 12:20 PM
shawazi shawazi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 123 shawazi User rank is Private First Class (20 - 50 Reputation Level)shawazi User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 9 m 51 sec
Reputation Power: 10
I'm thinking the same thing as you. It can't really iterate through them as it normally would. I specifically alerted every associative and got values, and then did my cleanup and saw everything turned to null. You'd think there has to be a better way though to ensure that things got cleaned properly. I'm working on an AJAX app where there's not one refresh so its important to clean the objects up.

Reply With Quote
  #4  
Old August 26th, 2008, 12:30 PM
URackEm's Avatar
URackEm URackEm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: San Francisco, CA
Posts: 78 URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 2 h 1 m
Reputation Power: 8
Send a message via Google Talk to URackEm
Is there a particular reason it HAS to be associative? I think it would be much more clean to use the default array indeces. Seems to me it would be more versatile, and a lot less room for typographical errors.

Reply With Quote
  #5  
Old August 26th, 2008, 12:31 PM
shawazi shawazi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 123 shawazi User rank is Private First Class (20 - 50 Reputation Level)shawazi User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 7 h 9 m 51 sec
Reputation Power: 10
Well i have it set up that the key is an ID of a DIV. It uses that to automatically build out onclicks and whatnot. I could redo that class so that i wont need that though possibly. It works fine now, so if that is the answer I have to write it down for later.

Reply With Quote
  #6  
Old August 26th, 2008, 12:47 PM
URackEm's Avatar
URackEm URackEm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: San Francisco, CA
Posts: 78 URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level)URackEm User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 2 h 1 m
Reputation Power: 8
Send a message via Google Talk to URackEm
Gotcha, no reason to change it if it is working.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Trouble with associative array

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