SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    passing an array to another function

    Hi,

    Is it possible to pass an array to another functions?

    I have my array:
    HTML Code:
    var arraySub = newArray();
       arraySub[0] = "Dave";
       arraySub[1] = "Bob";
       arraySub[2] = "Henry";
    which i then try to pass to another function :

    HTML Code:
    changeSub(2, Level,arraySub)
    However the function doesn't seem to recognise the array :
    HTML Code:
    alert(arraySub[0]);
    Can anyone see if i am doing anything wrong
    Eternity

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are a little verbose in your array declaration.

    var arraySub=['Tom','Dick',Harry');

    changeSub(2,Level,arraySub);

    The function you are calling has to handle arraySub:
    function changeSub(a1,a2,a3){
    alert(a3[2]);
    }

  3. #3
    SitePoint Addict
    Join Date
    Oct 2002
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats great - thanks.

    My JavaScript isn't as good as it should be!
    Eternity


Bookmarks

Posting Permissions

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