Hi folks,
My first post on here so please go easy on me :-)
I'm declaring a two-dimensional array like this:
Code:
var air = new Array();
air[0] = ['dragonfly', 'crane fly'];
air[1] = ['eagle', 'falcon'];
air[2] = ['jumbo jet','harrier'];
air[3] = [mosquito, wasp];
etc etc...
My question is, is there any way to return the number of 'rows' in this array (in this case 4). Have played around with array.length and various 'for' loops but I don't seem to be getting anywhere.
I'm sure there's an simple answer (as in mysql_num_rows in PHP) but I'm a bit new to javascript and can't see, to find the equivalent.
If each member of air is considered a row then using length on the air array will give you the number you're looking for.
You could also define your array like so:
Code:
var air = [
['dragonfly', 'crane fly'],
['eagle', 'falcon'],
['jumbo jet','harrier'],
['mosquito', 'wasp']
];
alert(air.length); //4
If I'm misunderstanding the question then let me know.
Hi,
...and thanks for getting back to me. No, you've got the question spot on and thanks for the answer. I originally thought I had to stick to the format I gave (the original is churned out of a database by php and comes in that format). Having checked it out though I think I might be able to make what you've shown me work with what I have already so, many thanks.
Bookmarks