There are two ways to access the members of a Javascript object.
Dot notation that uses an identifier to access a member:
obj.member;
A parenthesis designation that uses a string to access a member:
obj['member']
The latter uses a string to find an element, and you can just as easily use any expression. The value of the expression will be converted to a string, so that they are equivalent:
obj[{}] obj['[object Object]']
If your expression is already a string, it will be used as is, and in your case your variable contains a string that you can simply do:
document.getElementById('test').style[VARIABLE_NAME] = 'rotate(15deg)';
Paulpro
source share