I would like to do a backwards selection from the following JSON. I\'d like to extract the abbreviation for a particular state. In thi
There's no "automatic" way to do this. Your only option is to loop through the list until you find the value that matches the key.
But, if you need to do this multiple times, you should have the code rebuild the JSON object with key/values swapped, so that future lookups are faster. A simple way:
function swapJsonKeyValues(input) {
var one, output = {};
for (one in input) {
if (input.hasOwnProperty(one)) {
output[input[one]] = one;
}
}
return output;
}
var stateAbbrs = swapJsonKeyValues(States);