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

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -