Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在javascript的变量中可以有一个变量吗?_Javascript_Arrays_Variables - Fatal编程技术网

在javascript的变量中可以有一个变量吗?

在javascript的变量中可以有一个变量吗?,javascript,arrays,variables,Javascript,Arrays,Variables,我需要这样做: 第1章第1节标题为“狗” 第2章第1节标题为“猫” 第1章第2节标题为:“金鱼” 我希望能够用数组编写如下内容: section[0].chapter[0] = "Dogs"; section[0].chapter[1] = "Cats"; section[1].chapter[0] = "Goldfish"; 你是说像一个多维数组 关于stackoverflow的另一篇文章回答了如何创建二维数组的问题。 或者你可以使用一个“类”,虽然这可能是不必要的复杂 function

我需要这样做:

第1章第1节标题为“狗”

第2章第1节标题为“猫”

第1章第2节标题为:“金鱼”

我希望能够用数组编写如下内容:

section[0].chapter[0] = "Dogs";
section[0].chapter[1] = "Cats";
section[1].chapter[0] = "Goldfish";

你是说像一个多维数组


关于stackoverflow的另一篇文章回答了如何创建二维数组的问题。

或者你可以使用一个“类”,虽然这可能是不必要的复杂

function Section ()
{
  this.Chapters = new Array( 10 );
}

function CreateSection ()
{
  var sections = new Array ( 10 );

  sections[0] = new Section ();
  sections[0].Chapters[0] = "dogs";

  alert (  sections[0].Chapters[0] );
}

对你遇到什么麻烦了?谢谢!多维数组就是我要找的。。。我以前看到过一个例子,但它似乎不起作用,方法有点不同。