我怎么能在JavaScript中创建一个二维数组? [英] How can I create a two dimensional array in JavaScript?
本文介绍了我怎么能在JavaScript中创建一个二维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在线阅读和一些地方说,这是不可能的,有人说是,然后给出一个例子,反驳别人的例子,等等。
-
我如何申报在JavaScript中一个2维数组? (假设这是可能的)
-
我将如何访问它的成员? (
myArray的[0] [1]
或myArray的[0,1]
?)
解决方案
VAR项目= [[1,2],[3,4],[5,6];
警报(项目[0] [0]); // 1
I have been reading online and some places say it isn't possible, some say it is and then give an example and others refute the example, etc.
How do I declare a 2 dimensional array in JavaScript? (assuming it's possible)
How would I access its members? (
myArray[0][1]
ormyArray[0,1]
?)
解决方案
var items = [[1,2],[3,4],[5,6]];
alert(items[0][0]); // 1
这篇关于我怎么能在JavaScript中创建一个二维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文