...

View Full Version : Passing Array to Function



hiyatran
09-22-2011, 11:53 AM
I would like to pass an array to a function but how does the program know which array I would like to choose from??
Lets say I have 3 arrays and I would like to pass array C, to my function.
I checked the web but they only show if you have ONLY 1 array but NOT for multiple arrays.
How would I even go about doing this??



var arrA=new Array("fox.com","nbc.com","abc.com", "google.com");
var arrB=new Array("car","bike","boat", "plane");
var arrC=new Array("1","2","3", "4", "5", "6", "7", "8", "9");

function display(myArray){
myArray[1] = "changed";
}

display(myArray);

document.writeln(myArray[1]);

thanks

vwphillips
09-22-2011, 12:34 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
</head>

<body>
<script type="text/javascript">
/*<![CDATA[*/
var arrA=["fox.com","nbc.com","abc.com", "google.com"];
var arrB=["car","bike","boat", "plane"];
var arrC=["1","2","3", "4", "5", "6", "7", "8", "9"];
var myArray=[arrA,arrB,arrC];

function display(myArray){
myArray[1] = "changed";
}

display(myArray[1]);

document.writeln(myArray[1]);
/*]]>*/
</script>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum