0

配列内の要素、つまり別の配列内の要素、さらに別の配列内の要素を呼び出そうとしています。例えば....

  var a1 = ["1","2","3"];
  var a2 = ["4","5","6"];
  var a3 = ["7","8","9"];
  var a4 = ["10","11","12"];

  var b1 = ["a1","a2"];
  var b2 = ["a3","a4"];

  var c = ["b1","b2"];

  var x = c[0];

  console.log(x);

答えはx = b1

var x = c[0] b1[1] a2[2]答えが 6 になるように を定義するにはどうすればよいですか?

4

4 に答える 4

0

文字列ではなく、他の配列の要素として配列を定義します。

var a1 = [1, 2, 3];
...
var b1 = [a1, a2];
...
var c = [b1, b2];

var x = c[0][0][0]; // 1
于 2012-10-04T21:57:54.790 に答える
0

配列a1は実際には入っていませんb1— テキスト "a1" を含む文字列があるだけです。次のように定義した場合:

var a1 = ["1","2","3"];
var a2 = ["4","5","6"];
var a3 = ["7","8","9"];
var a4 = ["10","11","12"];

var b1 = [a1, a2];
var b2 = [a3, a4];

var c = [b1, b2];

と書くと「6」が得られますc[0][1][2]

于 2012-10-04T21:58:36.307 に答える
0

必要なのは、ネストされた配列です。

var a1 = ["1","2","3"];
var a2 = ["4","5","6"];
var a3 = ["7","8","9"];
var a4 = ["10","11","12"];

var b1 = [a1,a2];
var b2 = [a3,a4];

var c = [b1,b2];

var x = c[0][1][2];

console.log(x);
于 2012-10-04T21:58:37.887 に答える
0
var a1 = ["1","2","3"], a2 = ["4","5","6"], a3 = ["7","8","9"], a4 = ["10","11","12"];
var b1 = [a1,a2];
var b2 = [a3,a4];
var c = [b1,b2];

var x1 = c[0][0][0];
var x2 = c[0][0][1];
var x3 = c[0][0][2];

console.log(x1); //1 (1st/0 item of a1) from c
console.log(x2); //2 (2nd/1 item of a1) from c
console.log(x3); //3 (3rd/2 item of a1) from c

デモ

于 2012-10-04T22:00:53.050 に答える