我有一个数组,恰好填充有数组:[[1, "thing"], [2, "other thing"], [3, "still other thing"]]
我希望能够在其中一个数组中选择一个值,而不必将数组设置为临时变量,然后选择该项目。这可以吗?
最佳答案
您可以使用相同的“[]”语法对嵌套数组进行索引。
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
在该链接中搜索二维
关于javascript - 在数组中选择数组中的值; JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24981934/