Javascript + Multidimensional Arrays

Associate
Joined
3 Oct 2006
Posts
2,304
Location
London
I'm currently trying to teach myself javascript and was trying to create an *interactive* quiz with javascript. You type the your answer into the boxes and the javascript checks what you have typed against the array of answers for that question. (Obviously depending on the spelling means there is "more than one answer per question").

In php i'd create a multidimensional array using the same way I've tried to below, but it doesn't work in javascript. How would I go about creating a multidimensional array like the one below in javascript?

Code:
var answers = new Array()
answers[0][0] = "traffic jam";
answers[1][0] = "choc a block";
answers[2][0] = "crawling";
answers[3][0] = "gridlock";
answers[4][0] = "bumper to bumper";
answers[5][0] = "tailback";
answers[6][0] = "bottleneck";
answers[7][0] = "nose to tail";
answers[8][0] = "stationary";
answers[9][0] = "holdups";


Thanks
 
Ahhh, ok thanks. I have literally just found out that this also works...

Code:
var answers = new Array(new Array(),
			new Array(),
			new Array(),
			new Array(),
			new Array(),
			new Array(),
			new Array(),
			new Array(),
			new Array(),
			new Array());

answers[0][0] = "traffic jam";
answers[1][0] = "choc a block";
answers[2][0] = "crawling";
answers[3][0] = "gridlock";
answers[4][0] = "bumper to bumper";
answers[5][0] = "tailback";
answers[6][0] = "bottleneck";
answers[7][0] = "nose to tail";
answers[8][0] = "stationary";
answers[9][0] = "holdups";
 
Back
Top Bottom