Mapping multiple keys to the same value in a Javascript hash
Posted
by Bears will eat you
on Stack Overflow
See other posts from Stack Overflow
or by Bears will eat you
Published on 2010-03-24T21:20:31Z
Indexed on
2010/03/24
21:23 UTC
Read the original article
Hit count: 275
I use a Javascript hash object to store a set of numerical counters, set up like this [this is greatly simplified]:
var myHash = {
A: 0,
B: 0,
C: 0
};
Is there a way to make other keys, ones not explicitly in myHash
, map to keys that are? For instance, I'd like [again, this is simplified]:
myHash['A_prime']++; // or myHash.A_prime++;
to be exactly equivalent to
myHash['A']++; // or myHash.A++;
e.g. incrementing the value found at the key A
, not A_prime
.
© Stack Overflow or respective owner