Javascript - set a variable using concatenation of strings [duplicate]
问题 This question already has answers here : Use dynamic variable names in JavaScript (15 answers) Closed 6 years ago . Is it possible to set a variable by concatenating two strings together to form the name? If at all possible I'd like to determine what variable to set based on the class names of the objects that the user clicks. I know I can hard code a bunch of if/else if statements, but it would be really cool if I could reference the variables indirectly. I was thinking something like this: