I want to create an object which looks like the below code:
MyObject ={
"United Kingdom":{
"primary":{
},
"secondary":{
},
"service":{
},
},
"France":{
"primary":{
},
"secondary":{
},
"service":{
},
},
What I want to do is automatically generate the object from an array, so I have two arrays:
CountryList = ["United Kingdom", "France"]
MarketList = ["primary", "secondary", "service"]
I'm doing it through a for loop
for (var i = 0; i < CountryList.length; i++) {
for(var p = 0; p < MarketList.length; p++)
MyObject[CountryList[i]][MarketList[p]] = self;
}
However I'm getting an error:
Cannot set property 'primary' of undefined
Any ideas on where I am wrong? It functions fine when looping through the country list but when I want to nest the "Market" object inside I get a problem.
Thanks!