0
var obj = {a:1,b:2};
var str = "a";

console.log(obj.str);

This outputs undefined. What am i missing here ?

1 Answers1

4

You need to use []

var obj = {a:1,b:2};
var str = "a";

console.log(obj[str]);
Rainer Plumer
  • 3,693
  • 2
  • 24
  • 42