Edit:
From your comment:
extra_infoXXXXX holds a string
...it sounds like if subscid
contains "foo"
, you want to get the value of extra_infofoo
. If so, you'll need an object to look that up; otherwise, you'll be forced to use eval
.
If these extra_infoxxxx
variables are globals, you can look them up on window:
selector = window['extra_info' + subscid];
If not, I hate to say, you're stuck with eval
:
selector = eval('extra_info' + subscid); // Blech
But note that if you're doing that, it's best to step back and reevaluate (no pun!) your design. For instance, perhaps you could make an object with the extra info as properties:
var extra_info = {
foo: "bar"
};
Then you could look up the information like this:
selector = extra_info[subscid];
Original Answer:
It's very hard to tell from the information you've given, but I think you're looking for:
selector = extra_info[subscid];
...assuming that subscid
contains the name of the property on extra_info
that you want to access.
In JavaScript, you can access a property on an object using dotted notation and a literal property name:
x = foo.bar;
...or using bracketed notation and a string property name:
x = foo["bar"];
In the second case, the string can be the result of any expression. So for instance:
b = "bar";
x = foo[b];
or even
x = foo['b' + 'a' + 'r'];