Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] associative arrays question


  • From: javascript@xxxxxxxxxx (Christopher Basken)
  • Subject: [Javascript] associative arrays question
  • Date: Fri, 26 Apr 2002 18:55:30 -0400

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?