最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "cannot read property 0 of undefined" in 2d array - Stack Overflow

programmeradmin1浏览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]);

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
Add a ment  | 

3 Answers 3

Reset to default 6
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)

  1. 暂无评论