How to refer to object fields with a variable?

Viewed 52977

Let's asume that I have an object:

var obj = {"A":"a", "B":"b", "x":"y", "a":"b"}

When I want to refer to "A" I just write obj.A

How to do it when I have key in a variable, i.e.:

var key = "A";

Is there any function that returns a value or null (if key isn't in the object)?

2 Answers
Related