Update note: I believe this is different from the linked "duplicate" answer because I'm not asking how to use a variable name as the "name" (since I've shown I know how to do that), but rather, how to achieve the intended result below.
I currently have the custom data layer variable as an array that is populated in the following notation:
myArray.push({"name":"value"});
That said, the expected output should be like so:
[{"name1":"value1", "name2":"value2", "name3":"value3"}]
Now my current dilemma is that I need to add another item in the array, however, my "name" is stored in a variable.
Using the variable name leads to the variable name being used as the "name", so that won't work.
myArray.push({varName:"value"});
Results in:
[{"varName":"value"}]
I've also tried creating a new object, and inserting that in, but that just adds the object into the array without the correct "name".
var myObject = {};
myObject[varName] = "value";
myArray.push(myObject);
Results in:
[{"Message": {"varName":"value"}}]
Now, I'm out of ideas on how to go about with this, so any help is much appreciated!
TIA