L
Lee
J. J. Cale said:
I don't know that eval() is deprecated.
It's just usually not the best way to do something.
Assuming that this is in a web page, you can replace:
eval('data'+i)
with:
window['data'+i]
The fact that the variables are defined in a .js file
isn't really significant. The contents of that file
are evaluated in the context of the current window.
given that I have a js file included which is written programatically and I
can't change it. I would like to know how to do the following using
something other than the deprecated eval().
whats in the js file
var numArrays=something;
var data0 = new Array();
data0.name="name";
data0.data="some data";
var data1 = new Array();
data1.name="another name";
data1.data="some more data";
etc ....
function getData(arrayName) {
for ( var i=0;i<numArrays:i++) {
var el=eval('data'+i);
if (arrayName = = el.name) doSomething(el.data);
}
}
I don't know that eval() is deprecated.
It's just usually not the best way to do something.
Assuming that this is in a web page, you can replace:
eval('data'+i)
with:
window['data'+i]
The fact that the variables are defined in a .js file
isn't really significant. The contents of that file
are evaluated in the context of the current window.