2012-12-11 201 views

回答

1

您可以像訪問對象屬性:

myObject['property_name'] 

嘗試:

var obj = {}; 
obj.foo = 'bar'; 
var propName = 'foo'; 
console.log(obj[propName]); 
0

五言你可以在:

​(function(){ 
    var obj = {}; 
    obj.foo = 'bar'; 

    var key = 'foo'; 

    document.write(obj[key]); 
})()​