Global variables are bad! Another one about how they are bad...
You could always pass the array in a "buffer" parameter in your functions which is cleaner IMO.
Example:
<script type="text/javascript">
function WorkWithArray(myArray, someOtherParam)
{
if (myArray.constructor.toString().indexOf("Array") == -1)
return false;
//Work with myArray here
myArray[myArray.length] = 'blah';
return true;
}
</script>
In JavaScript, we have functions and we have arguments that we pass into those functions. But how JavaScript handles what you’re passing in is not always clear. When you start getting into object-oriented development, you may find yourself perplexed over why you have access to values sometimes but not other times.
When passing in a primitive type variable like a string or a number, the value is passed in by value. This means that any changes to that variable while in the function are completely separate from anything that happens outside the function.
Passing in an object (an array is an object), however, passes it in by reference. In this case, any property of that object is accessible within the function.
See JavaScript: Passing by Value or by Reference for more info.