JavaScript Globals - Method Handling
<p>I have multiple global arrays that a single method performs operations on. The method will only need to operate on one array at a time. I would like to accomplish this by passing a parameter to the method and then let the method decide which array it needs to modify based on that parameter. For example,</p>

<pre><code>var globalarray1;
var globalarray2;

Operate(globalarray1);

function Operate(globalarray){
   globalarray.push("test");
}
</code></pre>

<p>Of course, the code above only changes the value of the array local to the scope of the method. I know I can do something like this:</p>

<pre><code>var globalarray1;
var globalarray2;

Operate(1);

function Operate(flag){
   if (flag == 1){
      globalarray1.push("test1");
   }
   else if (flag == 2){
      globalarray2.push("test2")
   }
}
</code></pre>

<p>However, it just doesn't feel right. How can I change the value of the globals using parameters in a single method without using a bunch of conditional statements?</p>
