properties - How to create an object property from a variable value in JavaScript? -
this question has answer here:
i want add new property 'myobj', name 'string1' , give value of 'string2', when it returns 'undefined:
var myobj = new object; var = 'string1'; var b = 'string2'; myobj.a = b; alert(myobj.string1); //returns 'undefined' alert(myobj.a); //returns 'string2'
in other words: how create object property , give name stored in variable, not name of variable itself?
there's the dot notation , bracket notation
myobj[a] = b;
Comments
Post a Comment