I have the following Javascript defining an array of countries and their states ...
var countryStateMap = [{"CountryCode":"CA","Name":"Canada","States":[{"StateCode":"S!","CountryCode":"CA","Name":"State 1"},{"StateCode":"S2","CountryCode":"CA","Name":"State 2"}]},"CountryCode":"US","Name":"United States","States":[{"StateCode":"S1","CountryCode":"US","Name":"State 1"}]}];
Depending on the country that the user selects, I need to update the selection options for the states from the selected Country object. I know that I can index into a collection of countries with an index int like this ...
countryStateMap[0].States
I need a way to get the Country by CountryCode property. I know the following does not work, but what I would like to do is something like this ...
countryStateMap[CountryCode='CA'].States
Can this be achieved without completely rebuilding my collection structure or repeating over the set each time to find the one I want?
UPDATE: I accepted mVChr's answer because it worked and was the easiest solution, even if it required a second card.
, , , . , . ...
countryStateMap[$('#country').attr("selectedIndex")]
, .