How to set a global variable in function
<p>I read through similar topics, but couldn't find an answer.</p>

<p>Here is the code:</p>

<pre><code>foo_arr = ["a", "b", "c"]
bar_arr = ["x", "y"]

test(bar_arr);
document.write(bar);

function test(arr_name) {
    bar = Math.random()*arr_name.length;

    if (bar &lt; 1) {test(arr_name)}
}
</code></pre>

<p>As you can see I pass the array name to the function, but what if I need to pass a variable too? For instance</p>

<pre><code>test(bar, bar_arr);

function test(var_name, arr_name) {
    var_name = Math.random()*arr_name.length;
</code></pre>

<p>It won't work. Why and how to do this?</p>
