gpt4 book ai didi

javascript - 如何使用字符串变量访问字符串数组? JavaScript

转载 作者:行者123 更新时间:2023-12-02 18:34:13 24 4
gpt4 key购买 nike

我需要使用其他变量访问 h_00,有什么想法吗?

var json = '{"h_00":[["bus",28,"F"],["bus",71,"M"],["car",16,"M"]]}';
var arr_data = jQuery.parseJSON(json);

var access = "h_00";

alert(arr_data.access[0]);

最佳答案

使用bracket notation :

arr_data[access][0]; // ["bus", 28, "F"]

另外,这也不称为字符串数组。这是一个object .

关于javascript - 如何使用字符串变量访问字符串数组? JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17493914/

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