This question already has an answer here:
I have an object:
var obj = {fields : []};
And a variable:
var x = "property_name";
Now how do I use the value in the variable x as the property name for the object that I'm going
to push inside the array. I tried something like the one below but it takes x
literally and uses it as the property name, what I want to use is the value stored in the variable x
. Is that possible?
obj.fields.push({x : 'im a value'});