...is there some way of doing this with Javascript?
Not in the generic case, no. (Ugh, see below.) You can do it with global variables, like this:
var index;
for (index = 0; index < n.length; ++index) {
window[n[index]] = /*...whatever value you want the global to have...*/;
}
...but that only works for globals (and window is specific to the browser environment, although it's possible to do something analogous outside browsers), and barring some really specific reason for doing it, it's not a good idea.
You can create an object with properties for each of those names:
var obj = {};
var index;
for (index = 0; index < n.length; ++index) {
obj[n[index]] = /*...whatever value you want the global to have...*/;
}
...which is basically the global variable case, but with an object and not globals. But again, unless you have a really good reason to do it, there's little point (although it's not as harmful as creating a bunch of globals).
Okay, that's not quite true. You can do it like this:
var index;
for (index = 0; index < n.length; ++index) {
eval("var " + n[index]);
}
That will actually create variables in the current scope with the names from n. I don't recommend it. :-)