开发者

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

开发者 https://www.devze.com 2023-03-17 22:32 出处:网络
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开发

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开发者_JS百科. (or so I think)

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


var 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消