[Javascript] associative arrays question
Amanda Birmingham
lists at imladris.com
Fri Apr 26 18:21:33 CDT 2002
Use the for ... in construction, like this:
for (var strCurrentKey in theirScore) {
alert(theirScore[strCurrentKey]);
}
Also works for looping through object properties :) HTH.
Amanda Birmingham
Web Application Developer
At 06:55 PM 4/26/2002 -0400, you wrote:
>At least, I *think* they're called associative arrays.
>
>I created an associative array in the following manner:
>
>theirScore = new Array(3);
>
>theirScore["Bob"] = 0;
>theirScore["Fred"] = 0;
>theirScore["Sue"] = 0;
>
>This works fine, in the sense that I can fool around with those numeric
>values like so (where I pass it 'Sue' as an arg):
>
>function boostScore(who) {
> theirScore[who]++;
>}
>
>..and so on. The problem I'm running into is at the end, when I want to
>loop through the theirScore array, I can't seem to get normal indexing to
>work. theirScore["Sue"] returns the expected incremented value, but
>theirScore[2] returns 'undefined'.
>
>How do you loop through an associative array?
>
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
>
More information about the Javascript
mailing list