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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Posts
    143
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how can i check if array is multi dimension ?

    Hello
    how can i check if array contains more array AKA multi dimension array
    or it is regular 1 dimension array
    tnx

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A couple of ideas. I think the 1st makes more sense.

    if (typeof myArray[0][0] == 'undefined') {
    alert('1D')
    }

    or

    try {
    myArray[0][0] //some action
    } catch(e) {
    alert('1D')
    }

  • #3
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by Graeme Hackston
    A couple of ideas. I think the 1st makes more sense.

    if (typeof myArray[0][0] == 'undefined') {
    alert('1D')
    }

    or

    try {
    myArray[0][0] //some action
    } catch(e) {
    alert('1D')
    }
    That won't work correctly in Netscape. NS/Moz's Javascript interpretter has array indexing on strings, like with most languages:

    "hello"[0] == "h"

    Which presents difficulty for your method of find two-dimensional arrays.

    However, you should be able to do something-like:

    // assertion: arr[0] exists

    if (typeof arr[0][0] != "undefined" && arr[0][0].constructor == Array) {
    // two-dimensional
    }


  •  

    Posting Permissions

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