The reason you get the "element" is an undefined error, because:
var propertyName = "test"; var a = {propertyName: "test"};
equivalent to ..
var a = {"propertyName": "test"};
ie, you do not assign the value of propertyName as a key, you assign it the name of the property as a string.
Sciolist
source share