...

View Full Version : how can i check if array is multi dimension ?



frontline
06-11-2003, 08:49 AM
Hello
how can i check if array contains more array AKA multi dimension array
or it is regular 1 dimension array
tnx

Graeme Hackston
06-11-2003, 04:17 PM
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')
}

jkd
06-11-2003, 05:44 PM
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
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum