Convert String name into javascript variable name? -
this question has answer here:
- “variable” variables in javascript? 7 answers
problem example:
variable name: var product5519 = 10;
i can name in form of string i.e
var str = "product5519"
is there way convert variable name can use value assigned
product5519
i know 1 way solve problem i.e using eval(str)
if there way solve please tell?
once creating global variable right thing do, can add variable window
object, so:
window[str] = 42;
this works because variable lookups end trying window
object if variable not defined in inner scope.
Comments
Post a Comment