4

Does anyone know why this gives an error? I've been trying at it way too long and I can't seem to figure it out. It errors with "cannot read property 0 of undefined", but it is clearly defined. (or so I think)

var categorySix = [["test"]["test2"],["testing"]["one"],["two"]["three"]];
document.write(categorySix[0][0]);
wolfd
  • 127
  • 1
  • 3
  • 9

3 Answers3

6
var categorySix = [["test","test2"],["testing","one"],["two","three"]];

Your syntax is off.

James Montagne
  • 77,516
  • 14
  • 110
  • 130
1

You are declaring your 2D array wrong.

Try this :

var categorySix = [["test","test2"],["testing","one"],["two","three"]];
leandre_b
  • 331
  • 1
  • 8
0

You are not correctly creating the array.

I believe it should be

var categorySix = [["test","test2"],["testing","one"],["two","three"]];
document.write(categorySix[0][0]);

As per How can I create a two dimensional array in JavaScript?

Community
  • 1
  • 1
Drazisil
  • 3,070
  • 4
  • 33
  • 53