我有一个数组,恰好填充了数组:[[1, "thing"], [2, "other thing"], [3, "still other thing"]]
我希望能够在其中一个数组中选择一个值,而不必将数组作为临时变量,然后选择该项。可以这样做吗?
答案 0 :(得分:2)
您可以使用相同的' []'索引到嵌套数组中。句法。
var arr = [[1, "thing"], [2, "other thing"], [3, "still other thing"]];
console.log(arr[0]); // [1, "thing"]
console.log(arr[0][0]); // 1
供参考,https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
在该链接中搜索二维