Firstly appologies for the poor title, not sure how to explain this in one line.
I have this Javascript function (stripped down for the purpose of the question)…
function change_col(zone){
var objects= zone1227.getObjects();
}
I am passing in an integer into the function. Where I have “zone1227”, I want that 1227 to be the integer I pass in.
I’ve tried this;
var zonename = "zone" + zone;
var objects= zonename.getObjects();
but that doesn’t work.
Is this possible? The functions do exist for every possible integer passed in, but I was hoping to keep the code compact rather than a long list of if statements with hardcoded function names.
Since
zone1227is apparently a global variable, it can also be written aswindow.zone1227or aswindow['zone1227']. This means that you can achieve what you describe, by writing this:Nonetheless, I agree with Interrobang’s comment above. This is not a good way to accomplish whatever it is that you really want to accomplish. You should not be referring to global variables via strings containing their names.