I have 2 variables in a script tag that get populated with string values.
I also have an .each loop that goes through each select box I have on the page. I want a way to append the index value of the loop to the name of the variable, and retrieve its value.
var secQuestion1 = "bla"
var secQuestion2 = "bla"
selectbox.each(function( index ) {
var question = ['secQuestion' + (index+1) ];
console.log("question = ", ['secQuestion' + (index+1)] )
});
I thought I might be able to use bracket notation to retrieve the value.
Any ideas on how to do this, so on each index in the loop I would get my questions values?
it depends in what context your code is running, if your variables are global then you can do
you can also put them in an object and access them that way