访问一般的javascript对象属性

时间:2012-11-19 08:51:29

标签: javascript javascript-objects

我已经设置了这个js对象:

 var tableTypes = {
        "stockRcmnd":{
            "name":"stockRcmnd",
            "columns": ['1','2', '3']
        }, 
        "stockChange":{
            "name":"stockChange",
            "columns": ['4','5', '6']
        }
    };

现在,我想动态地获取列:

property = "stockChange";

columns = tableTypes.{property}.columns;

property = "stockRcmnd";

columns = tableTypes.{property}.columns;

here是jsfiddle;

任何想法怎么做?

2 个答案:

答案 0 :(得分:1)

也可以在JavaScript中访问对象属性:

tableTypes[property].columns

答案 1 :(得分:0)

只需:

   tableTypes['stockRcmnd'].name