Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Array to Function

Status
Not open for further replies.

hiyatran

Technical User
Aug 7, 2010
21
CA
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??


Code:
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


 
Hi

You should read about functions ( generally, not only in JavaScript ) as there is nothing special there regarding the arrays. The Parameter (computer programming) Wikipedia article is also a good start.

myArray is called formal parameter and is used only in the declaration.
When calling the array the actual parameter is passed and will undergo the operations described in the declaration. That will be arrC in your case.
Code:
[COLOR=darkgoldenrod]display[/color][teal]([/teal]arrC[teal]);[/teal]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top