I'm trying to create a javascript object that contains nested properties where some of the property names need to be generated dynamically. The following is what I have that is already working:
postObject[campaignObj.campaignName] = {
"campaignSet" : {
"groupName" : groupObj.adGroupName,
"textads" : groupObj.textAds
}
}
However, I need "campaignSet" to be named dynamically from a variable or other object value. The possibility exists for several campaign sets to exist that must all be contained under postObject[campaignObj.campaignName].
My thought process was that something like the options below should work
postObject[campaignObj.campaignName] = {
[campaignObj.campaignSet] : {
"groupName" : groupObj.adGroupName,
"textads" : groupObj.textAds
}
}
but this code above keeps throwing an "Invalid property ID" error.
So I tried this
postObject[campaignObj.campaignName] = {
campaignObj.campaignSet : {
"groupName" : groupObj.adGroupName,
"textads" : groupObj.textAds
}
}
Which caused "Missing : after property ID".
I feel this should be pretty straightforward but it continues to elude me. Any help would be greatly appreciated.