wolfd
wolfd

Reputation: 127

"cannot read property 0 of undefined" in 2d array

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]);

Upvotes: 4

Views: 7420

Answers (3)

Drazisil
Drazisil

Reputation: 3373

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?

Upvotes: 0

leandre_b
leandre_b

Reputation: 331

You are declaring your 2D array wrong.

Try this :

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

Upvotes: 1

James Montagne
James Montagne

Reputation: 78780

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

Your syntax is off.

Upvotes: 6

Related Questions