質問

I have a problem in declaring a inicialiting an object. When I define an object and pass by reference a string does not recognize me and fails. The object is as follows:

markerGroups = {"america": [], "europa": [], "asia": [],"africa": [], "oceania": [] };

Well, it works correctly, but if I change, for example, "america" ​​putting var amer = "america"​​, like this:

var amer = "america"; 
markerGroups = {amer: [], "europa": [], "asia": [],"africa": [], "oceania": [] };

It does not work. What i have to do for resolve this?

役に立ちましたか?

解決 2

something like this;

var markerGroups = {}
var amer = "america"; 
markerGroups[amer] = [];

他のヒント

In JavaScript, you don't need to quote your object keys. So amer: [] is creating the literal key "amer".

You need to use the [] method to do this:

var amer = "america"; 

markerGroups = {...};
markerGroups[amer] = [];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top