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?
- Follow-Ups:
- [Javascript] associative arrays question
- From: Amanda Birmingham
- [Javascript] associative arrays question
- Prev by Date: [Javascript] How do I refer to whitespace characters?
- Next by Date: [Javascript] associative arrays question
- Previous by thread: [Javascript] Please help: problem with Javascript 'this' keyword in nested objects!
- Next by thread: [Javascript] associative arrays question
- Index(es):