Convert String name into javascript variable name? -


this question has answer here:

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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -