How do I count 'rows' in a two dimensional array?
My first post on here so please go easy on me :-)
I'm declaring a two-dimensional array like this:
var air = new Array();
air = ['dragonfly', 'crane fly'];
air = ['eagle', 'falcon'];
air = ['jumbo jet','harrier'];
air = [mosquito, wasp];
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.
Thanks in advance,
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:
If I'm misunderstanding the question then let me know.
var air = [
['dragonfly', 'crane fly'],
...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.
Have a good one
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread