There is a specific object I am working with that will always have 2 properties, never more. The object looks like this:
var people = {
'John': { ... },
'Peter': { ... }
}
In addition, there is a variable var name = 'John'
.
I am looking for an efficient way to retrieve the value of the property 'Peter'
when the value of name
is 'John'
. This should be done without explicitly coding the names John and Peter in the function. The goal is to dynamically fetch the opposite property based on the value stored in the name
variable.