Possible Duplicates:
Is there a way to access a javascript variable using a string that contains the name of the variable?
JavaScript: Get local variable dynamicly by name string
A simple code to illustrate my problem -
var chat_1 = "one";
var chat_2 = "two";
var id = "1";
var new = ?? variabalize( 'chat_' + id )
I want the variable new to be assigned the value of variable - chat_1 which is "one"
Stop. Reorganise your code. If you want to select variables with a variable, then there has to be a logical grouping for them. Make it explicit.
var chat = {
"1": "one",
"2": "two"
};
var id = 1;
var new_is_a_keyword_and_cant_be_an_identifier = chat[id];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With