I'm working on existing Javascript code, which uses datasets stored in objects which are named data1, data2, etc. The numbers are IDs taken from a database.
Now, I need to write a little additional function which takes the IDs as input, then constructs the appropriate object name using that Id, and then passes that object to a function as a parameter.
So, something like:
function doStuff(id){
var objname="data"+id;
//now, I need to pass the object (not just the name) to a function
someFunction(objname); //this obviously doesn't work, because it just passes the object name as a string
}
So, how do I pass the actual object to the function, given that I have the object name?
The question sounds elementary, and I assume there's a method which does just this, but google doesn't seem to help.
data1 = 'one';anddata2 = 'two';, right?