yongsing
asked on
Hashtable
Is there a hashtable object in javascript that I can use?
For example, I have the following values:
1W
1M
2M
...
And I want to map to these values:
1 Week
1 Month
2 Months
...
For example, I have the following values:
1W
1M
2M
...
And I want to map to these values:
1 Week
1 Month
2 Months
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script type="text/javascript">
var hash = new Array();
hash["a"] = "foo";
hash["b"] = "bar";
hash["c"] = "baz";
// first, show you can get each element back out
var str = "";
str += "in my hash, key 'a' has value of: " + hash["a"];
str += "\nin my hash, key 'b' has value of: " + hash["b"];
str += "\nin my hash, key 'c' has value of: " + hash["c"];
alert(str);
// now, getting a collection of keys (and values)
var keyStr = "";
var valStr = "";
for (var i in hash)
{
keyStr += i +"\n";
valStr += hash[i] + "\n";
}
alert("keys:\n" + keyStr + "values:\n" + valStr);
</script>
Hope that helps.