javascript - How to use a functions parameter as attribute in dot notation with an object -
i have function parameter string. want use string attribut in object. here's example how be:
var x = "somestring" function foo(attribute) { someobj.attribute = "something"; } foo(x);
use subscript []
notation dynamic keys:
someobj[attribute] = "something";
code
var x = "somestring"; var someobj = {}; function foo(attribute) { someobj[attribute] = "something"; } foo(x);
Comments
Post a Comment