2014-03-24 38 views
0

的JavaScript訪問對象我有一個JavaScript對象是這樣的:帶通配符關鍵

e {_layers: Object, _initHooksCalled: true, _leaflet_id: 25, _map: e, constructor: function…} 
    _initHooksCalled: true 
    _layers: Object 
    38: e 
    _container: g 
    _ini 
    _mradius: 107 

我要訪問radius。然而,編號38因案件而異。所以我在尋找某種通配符。

myObject._layers[??]._mRadius 
+0

這會否是該對象的唯一因素? – thefourtheye

+0

是的。該值僅從對象變爲對象。 – ustroetz

回答

2

你可以這樣做:

myObject._layers[Object.keys(myObject._layers)[0]]._mradius 
+0

這隻會讓我'Uncaught TypeError:Object.keys在非對象上調用' – ustroetz

+0

那麼,如果你的對象被稱爲「e」(?),那麼你只需用e替換myObject。 – zvona

+0

我的對象實際上被稱爲'myObject'。 'myObject [Object.keys(myObject)'也能正常工作。但是,當我添加'_layers'部分時,它不起作用。 – ustroetz