gpt4 book ai didi

javascript - 在数组中选择数组中的值; JavaScript

转载 作者:行者123 更新时间:2023-12-02 17:09:05 24 4
gpt4 key购买 nike

我有一个数组,恰好填充有数组:[[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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com