gpt4 book ai didi

javascript - 从由 Array 组成的对象中获取值

转载 作者:行者123 更新时间:2023-11-29 18:55:14 27 4
gpt4 key购买 nike

我有一个只包含一个 Array(17) 的对象。我想从此数组中获取特定值,例如 index = 4 -> 1523181939

我怎样才能得到它?

enter image description here

我通过运行得到一个控制台结果:

this.temp = this.flights['states'];
console.log(this.temp);
console.log(typeof this.temp);

我的对象 this.flights 的形式是

{time: 1523183848, states: Array(1)}
states: [Array(17)]
time: 1523183848
__proto__: Object

当我调用 this.flights['states'] 时,我得到:

[Array(17)]

最后,在调用 this.flights['states'][0][4] 时出现错误:

ERROR TypeError: Cannot read property '0' of undefined

开始我从 Opensky-Network Api 获取的航类对象:

{
"time": 1523183840,
"states": [
[
"89906e",
"EVA857 ",
"Taiwan",
1523183838,
1523183839,
121.2966,
25.1178,
716.28,
false,
111.38,
50.06,
8.78,
null,
746.76,
null,
false,
0
]
]
}

最佳答案

工作代码如下。

像这样访问对象上的数组元素 this.temp = this.flights.states[0][4];

像下面那样做:

var flights = {"time":1523183840,"states":[["89906e","EVA857  ","Taiwan",1523183838,1523183839,121.2966,25.1178,716.28,false,111.38,50.06,8.78,null,746.76,null,false,0]]};



this.temp = this.flights.states[0][4];
console.log(this.temp);
console.log(typeof this.temp);

立即查看。根据您的要求,它现在是工作代码。

关于javascript - 从由 Array 组成的对象中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49716759/

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