Attempting to access a specific property value from a JavaScript object, I have written the following code:
for (key in map.regions) {
console.log(key);
console.log(states);
console.log(states.key);
}
The key variable will contain something like "US-VA"
.
The states variable should resemble this:
Object {US-VA: Object, US-PA: Object, US-TN: Object, US-ID: Object, US-NV: Object…}
(As displayed in Chrome).
Despite expecting to retrieve the object corresponding to the key by using console.log on states.key, only "undefined" is returned. What mistake am I making here? How can I effectively obtain the values from the states variable that match the key?