Web Design Forum: Print two-dimensional array - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Print two-dimensional array

#1 User is offline   RiskyShenanigan 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 84
  • Joined: 09-July 11
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:Web Developer

Posted 18 January 2012 - 11:46 AM

Hi, I wish to know how to print out a two-dimensional array with a for loop, I know how to do this with a single array but unsure with two-dimensional.

function saveBooking(){
		
		var booking = {
			tableNo : $('#table_no').val(),
			customer : $('#customer').val(),
			seats : $('#seats').val(),
			cost : $('#cost').val()
		}
			
		/*for(i=0;i<booking.length;++i){
			document.write(booking[i]);
		}*/
	}

0

#2 User is online   andyl 

  • White space enthusiast
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,535
  • Joined: 21-January 10
  • Reputation: 210
  • Gender:Male
  • Location:Surrey
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 18 January 2012 - 12:01 PM

That's not a 2D array, it's a JavaScript object. Either way, you can iterate through it using jQuery like so:

$.each(booking, function(key, val){
    document.write(key + ": " + val);
});

2

#3 User is offline   RiskyShenanigan 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 84
  • Joined: 09-July 11
  • Reputation: 0
  • Gender:Male
  • Experience:Beginner
  • Area of Expertise:Web Developer

Posted 18 January 2012 - 12:47 PM

Thanks, working now.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users