此数组中x和y的位置是什么:
var a = [ [1,2], [x], [3, [y]] ];
我对这里的语法有点困惑。
它会是:
a[1] = x and a[2][1] = y?
或者引入一组新的方括号意味着我们改为:
a[1][0] = x and a[2][1][0] = y?
答案 0 :(得分:1)
让我们一起发现;)
var a = [ [1,2], [x], [3,[y]]];
如果你逐行写出:
var a = [
[1,2], // new array with index 0 containing 1 and 2 => a[0][0] = 1 and a[0][1] = 2
[x], // new array with index 1 containing x => a[1][0] = x
[3,[y]] // new array with index 2 containing 3 and array containing y a[2][0] = 3 a[2][1][0] = y
];
换句话说,x = a [1] [0]
答案 1 :(得分:0)
var x = "x";
var y = "y";
var a = [ [1,2], [x], [3, [y]] ];
console.log(a[1][0]);
console.log(a[2][1][0]);