If I have a set of key/value pairs like this:
WX Code WMO WX Code Description
------- -----------------------
00 No significant weather
04 Haze
10 Mist
20 Fog detected in last hour
21 Precip detected in last hour
22 Drizzle detected in last hour
23 Rain detected in last hour
24 Snow detected in last hour
that I want to access as an array by the integer code, what is the best way to format the array? If I try this
var arrWXcodes = [
{00:"No significant weather"},
{04:"Haze"},
{10:"Mist"},
{20:"Fog detected in last hour"},
{21:"Precip detected in last hour"},
{22:"Drizzle detected in last hour"},
{23:"Rain detected in last hour"},
{24:"Snow detected in last hour"}];
And I try to access the array to get, say "Haze" like so, I don't get what I want. I want to access the array by the key's integer value, not the position in the array
arrWXcodes["04"]
undefined
arrWXcodes[04]
Object { 21: "Precip detected in last hour" }
What would be the best data structure and access method to be able to use an integer key to access the array and get the expected value?