I have a javascript variable called temp.
ultimately, temp will equal one of many strings, let’s say for now it equals "stack".
how can I set the variable (in this case stack, which is an existing global variable) to equal the string "stack", dynamically?
So if at another point in time, temp is set to "overflow", how can i set overflow = "overflow"?
Thanks for your help!
i’ve seen some answers mention eval and others mention using bracket ~ this[variable], but can’t seem to figure this out..
The easiest way to achieve this is to create an object to hold these dynamic variable assignments.
you an then access ‘overflow’ with either
tempVars.overflowortempVars['overflow']. Technically, you can assign global variables this way by using thewindowobject instead oftempVars, but this is a bad idea in general.