使用JavaScript创建多维数组

时间:2018-07-03 13:51:49

标签: arrays multidimensional-array

我们已经用HTML开发了一个应用程序,我们想定义多维数组。例如,我们有5条记录,然后我们要使用java脚本创建下面显示的数组。任何人都有示例代码来生成数组。

0       1       2       3       4       5

0 0:00 0:12 0:06 0:00 0:06 0:06 1 0:11 0:00 0:12 0:11 0:15 0:13 2 0:05 0:12 0:00 0:05 0:06 0:00 3 0:00 0:12 0:06 0:00 0:06 0:06 4 0:06 0:15 0:05 0:06 0:00 0:05 5 0:05 0:12 0:00 0:05 0:06 0:00

谢谢!

2 个答案:

答案 0 :(得分:0)

这是最简单的方法。

var arr = [
  [0, 1, 2],
  [44, 34, 0],
  [9, 2, 4]
];

console.log(arr [2] [1])//输出2

答案 1 :(得分:0)

var arr = [
    ["0:00", "0:12", "0:06", "0:00", "0:06", "0:06"],
    ["0:11", "0:00", "0:12", "0:11", "0:15", "0:13"], 
    ["0:05", "0:12", "0:00", "0:05", "0:06", "0:00"],
    ["0:00", "0:12", "0:06", "0:00", "0:06", "0:06"],
    ["0:06", "0:15", "0:05", "0:06", "0:00", "0:05"],
    ["0:05", "0:12", "0:00", "0:05", "0:06", "0:00"]
]

其中arr[2]的值为["0:05", "0:12", "0:00", "0:05", "0:06", "0:00"]

var dict = {
    0: ["0:00", "0:12", "0:06", "0:00", "0:06", "0:06"],
    1: ["0:11", "0:00", "0:12", "0:11", "0:15", "0:13"], 
    2: ["0:05", "0:12", "0:00", "0:05", "0:06", "0:00"],
    3: ["0:00", "0:12", "0:06", "0:00", "0:06", "0:06"],
    4: ["0:06", "0:15", "0:05", "0:06", "0:00", "0:05"],
    5: ["0:05", "0:12", "0:00", "0:05", "0:06", "0:00"]
}

其中dict[2]的值为["0:05", "0:12", "0:00", "0:05", "0:06", "0:00"]