Click to See Complete Forum and Search --> : Array as a parameter


spufi
09-24-2003, 06:56 PM
Can I pass the whole array as a parameter, or does it have to be one instance of it, ie myArray[0]? I want to pass the whole array and then loop through the array when I'm inside my function. If I can only pass an instance of the array, then I have to use the function within a loop, and it gets a lot uglier doing it that way.

Anybody know if Java lets you pass the whole array, or not? I want to convert my work over to Java at some point anyway, so I'm wondering.

pyro
09-24-2003, 09:19 PM
Don't know about Java, but in JavaScript, you can indeed pass an array as a parameter to a function. Take a look at this example:

<script type="text/javascript">

function test(ary) {
for (i in ary) {
alert (ary[i]);
}
}

ary = new Array("one","two","three");
test(ary);

</script>