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]);
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]);
Share
Improve this question
asked Jul 6, 2011 at 14:20
wolfdwolfd
1271 gold badge3 silver badges9 bronze badges
1
- Please remember to mark an answer as accepted if your issue is resolved. – Drazisil Commented Jul 6, 2011 at 14:34
3 Answers
Reset to default 6var categorySix = [["test","test2"],["testing","one"],["two","three"]];
Your syntax is off.
You are declaring your 2D array wrong.
Try this :
var categorySix = [["test","test2"],["testing","one"],["two","three"]];
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?