javascript 如何从给出两个数组输出的API中提取单个数组数据?

kd3sttzy  于 2022-11-27  发布在  Java
关注(0)|答案(1)|浏览(122)

I am facing a problem, I can't extract data from just one array - temperature. I tried to put it into another array, but all I managed to do was put there all the data. Any advice? Thank you in advance!
Console output of the function I use: { latitude: 51.75, longitude: 19.5, generationtime_ms: 0.28395652770996094, utc_offset_seconds: 0, timezone: 'GMT', timezone_abbreviation: 'GMT', elevation: 218, hourly_units: { time: 'iso8601', temperature_2m: '°C' }, hourly: { time: [ '2022-11-26T00:00', '2022-11-26T01:00', '2022-11-26T02:00', '2022-11-26T03:00', '2022-11-26T04:00', '2022-11-26T05:00', '2022-11-26T06:00', '2022-11-26T07:00', '2022-11-26T08:00', '2022-11-26T09:00', '2022-11-26T10:00', '2022-11-26T11:00', '2022-11-26T12:00', '2022-11-26T13:00', '2022-11-26T14:00', '2022-11-26T15:00', '2022-11-26T16:00', '2022-11-26T17:00', '2022-11-26T18:00', '2022-11-26T19:00', '2022-11-26T20:00', '2022-11-26T21:00', '2022-11-26T22:00', '2022-11-26T23:00', '2022-11-27T00:00', '2022-11-27T01:00', '2022-11-27T02:00', '2022-11-27T03:00', '2022-11-27T04:00', '2022-11-27T05:00', '2022-11-27T06:00', '2022-11-27T07:00', '2022-11-27T08:00', '2022-11-27T09:00', '2022-11-27T10:00', '2022-11-27T11:00', '2022-11-27T12:00', '2022-11-27T13:00', '2022-11-27T14:00', '2022-11-27T15:00', '2022-11-27T16:00', '2022-11-27T17:00', '2022-11-27T18:00', '2022-11-27T19:00', '2022-11-27T20:00', '2022-11-27T21:00', '2022-11-27T22:00', '2022-11-27T23:00', '2022-11-28T00:00', '2022-11-28T01:00', '2022-11-28T02:00', '2022-11-28T03:00', '2022-11-28T04:00', '2022-11-28T05:00', '2022-11-28T06:00', '2022-11-28T07:00', '2022-11-28T08:00', '2022-11-28T09:00', '2022-11-28T10:00', '2022-11-28T11:00', '2022-11-28T12:00', '2022-11-28T13:00', '2022-11-28T14:00', '2022-11-28T15:00', '2022-11-28T16:00', '2022-11-28T17:00', '2022-11-28T18:00', '2022-11-28T19:00', '2022-11-28T20:00', '2022-11-28T21:00', '2022-11-28T22:00', '2022-11-28T23:00', '2022-11-29T00:00', '2022-11-29T01:00', '2022-11-29T02:00', '2022-11-29T03:00', '2022-11-29T04:00', '2022-11-29T05:00', '2022-11-29T06:00', '2022-11-29T07:00', '2022-11-29T08:00', '2022-11-29T09:00', '2022-11-29T10:00', '2022-11-29T11:00', '2022-11-29T12:00', '2022-11-29T13:00', '2022-11-29T14:00', '2022-11-29T15:00', '2022-11-29T16:00', '2022-11-29T17:00', '2022-11-29T18:00', '2022-11-29T19:00', '2022-11-29T20:00', '2022-11-29T21:00', '2022-11-29T22:00', '2022-11-29T23:00', '2022-11-30T00:00', '2022-11-30T01:00', '2022-11-30T02:00', '2022-11-30T03:00', 68 more items ], temperature_2m: [ 2.4, 2.3, 2.1, 1.9, 1.8, 1.7, 1.8, 1.7, 1.9, 2.3, 2.5, 2.6, 2.1, 1.1, 0.7, 0.5, 0.2, 0, 0.1, 0.1, -0.1, -0.1, -0.1, -0.1, -0.2, -0.2, -0, 0.1, 0, -0.1, -0.1, -0.1, 0.2, 1, 1.5, 2, 2.1, 2.1, 2, 1.7, 1.5, 1.3, 1.2, 0.9, 0.9, 0.9, 0.7, 0.6, 0.2, -0.1, -0.1, -0.1, -0.1, -0.2, -0.3, -0.4, -0.3, 0.4, 1.4, 1.8, 1.5, 1.4, 1.4, 0.9, 0.3, -0, -0.1, -0.2, -0.3, -0.3, -0.3, -0.5, -0.8, -0.9, -1, -1.1, -1.3, -0.3, -0.3, -0.4, -0.5, -0.6, -0.8, -0.8, -0.8, -0.8, -0.8, -0.9, -1,
As posted above, tried to extract one array from whole data asset

r6hnlfcb

r6hnlfcb1#

从这里我可以看到,它是一个嵌套的对象,而不是一个数组,你试过吗

data.hourly.temperature_2m

这将为您提供temperature_2m数据,如果不成功,请尝试检查typeof数据是字符串还是对象

相关问题