从Value获取单个密钥
我想从以下JSON中做一个向后选择.我想提取特定状态的缩写.在这种情况下,缩写是关键,我开始的值是值.
当然,我可以遍历每个值,将值与我的值进行比较,并在匹配时选择键.这是接近这样的最佳方式吗?或者,还有更好的方法?
反转JSON数据
另一种选择是在处理过程中尽早反转这些数据,以便在交换键/值时给自己一组类似的值.我有兴趣看到有效地做到这一点的方法.
var States = {AL: 'Alabama',AK: 'Alaska',AZ: 'Arizona',AR: 'Arkansas',CA: 'California',CO: 'Colorado',CT: 'Connecticut',DE: 'Delaware',DC: 'District of Columbia',FL: 'Florida',GA: 'Georgia',HI: 'Hawaii',ID: 'Idaho',IL: 'Illinois',IN: 'Indiana',IA: 'Iowa',KS: 'Kansas',KY: 'Kentucky',LA: 'Louisiana',ME: 'Maine',MD: 'Maryland',MA: 'Massachusetts',MI: 'Michigan',MN: 'Minnesota',MO: 'Missouri',MT: 'Montana',NE: 'Nebraska',NV: 'Nevada',NH: 'New Hampshire',NJ: 'New Jersey',NM: 'New Mexico',NY: 'New York',NC: 'North Carolina',ND: 'North Dakota',OH: 'Ohio',OK: 'Oklahoma',OR: 'Oregon',PA: 'Pennsylvania',RI: 'Rhode Island',SC: 'South Carolina',SD: 'South Dakota',TN: 'Tennessee',TX: 'Texas',UT: 'Utah',VT: 'Vermont',VA: 'Virginia',WA: 'Washington',WV: 'West Virginia',WI: 'Wisconsin',WY: 'Wyoming'};