views:

62

answers:

2

Hi, I have like this

var house = {'floor':{'one':'3 people','two':'1 people'}}
var tmp = 'one';

and I want to call like this..

console.log(house.floor.tmp) // expecting '3 people' result

tmp value will get from somewhere dynamically but it's not working. How can I solve this?

+7  A: 

Try

console.log(house.floor[tmp]);

Should work for you.

In this scenario you are just using indexing notation to reference the object property, since the engine won't resolve tmp to the value of 'one' using dot notation.

Quintin Robinson
Perfect answer. Thanks :)
Devyn
A: 

i was trying this for long time. thank you very much :)

Adarsh