Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    39
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Passing Array to Function

    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

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,518
    Thanks
    3
    Thanked 506 Times in 493 Posts
    Code:
    <!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>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •