Development Javascript woes... (multidimentional arrays)

Discussion in 'Software' started by RPC_Student, 4 Jun 2004.

  1. RPC_Student

    RPC_Student Banned

    Joined:
    8 Oct 2003
    Posts:
    182
    Likes Received:
    0
    I need a multidimentional array.

    Javascript does not support multidimentional arrays.

    got a solution?

    I need this for a dropdown menu:

    submenustrings [ menu ] [ item ] [ item values ]

    this has been annoying the hell out of me for ages now -- I might even have to resort to placing some VBscript in my webbitty site.
     
  2. JuMpErFLY

    JuMpErFLY Minimodder

    Joined:
    13 Mar 2003
    Posts:
    882
    Likes Received:
    1
    Could you use 3 separate arrays?
     
  3. RPC_Student

    RPC_Student Banned

    Joined:
    8 Oct 2003
    Posts:
    182
    Likes Received:
    0
    I did when I was posting, but had problems using it.

    Its all fixed now, however -- its a shame multidimentional arrays have to be done is such a confusingly complicated way; its moronic.
     
  4. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    so are a lot of high-level languages, cobol or camel for instance.

    or the brackets in VB () been the same for functions as they are arrays, nice.
     
  5. batsman

    batsman the quiet one

    Joined:
    14 Nov 2001
    Posts:
    1,088
    Likes Received:
    0
    what about if you used an object that contained arrays.

    just an idea, i dont know javascript
     
  6. Hepath

    Hepath Minimodder

    Joined:
    20 Oct 2003
    Posts:
    730
    Likes Received:
    0
    Just caught this...
    'tis true that Javascript does nto support multidimensional arrays (boo!) but you can use object to get arround this as implied by batsman

    At the end of the day a JS Array is just an object so you can use that knowledge. When an Array is created it really creates an object based on the given arguments.

    here's a very simple 2D array:


    // declare an array
    var arrUserPassword = new Array(10);

    // define what our array will hold
    function UserDetails(name, pwd)
    {
    this.name = name;
    this.pwd = pwd
    }

    //add items
    arrUserPassword[0] = new UserDetails("Admin", "god")
    arrUserPassword[1] = new UserDetails("Stu", "muppet")

    To turn this into a 3d array I could just create another object which could be an array....


    // define what our array will hold
    function UserDetails(name, pwd, history)
    {
    this.name = name;
    this.pwd = pwd
    this.history = history
    }

    var pwdhist = new Array("a", "b", "c");

    //add items
    arrUserPassword[0] = new UserDetails("Admin", "god", pwdHist)

    You can then use accessor functions via the prototype keyword to retrieve items from the 3d dimension


    P.S This is written from memory and might [not] work - but it might help for future stuff/info
     

Share This Page