回答編集履歴
3
求めているものではない気がしてきたので削除
answer
CHANGED
@@ -33,20 +33,4 @@
|
|
33
33
|
if (endpoint === "onecall") console.log(json["hourly"][0]["temp"]);
|
34
34
|
})
|
35
35
|
})
|
36
|
-
```
|
37
|
-
|
38
|
-
---
|
39
|
-
|
40
|
-
# 追記
|
41
|
-
|
42
|
-
私が書くなら、オブジェクトをまとめてしまうかもですね。
|
43
|
-
|
44
|
-
```js
|
45
|
-
Promise.all(url.map(async ([endpoint, dataUrl]) => [endpoint,
|
46
|
-
await fetch(dataUrl, {
|
47
|
-
method: "GET",
|
48
|
-
})
|
49
|
-
.then(response => response.json())
|
50
|
-
]))
|
51
|
-
.then(x => console.log(Object.fromEntries(x).onecall.hourly[0].temp))
|
52
36
|
```
|
2
追記
answer
CHANGED
@@ -33,4 +33,20 @@
|
|
33
33
|
if (endpoint === "onecall") console.log(json["hourly"][0]["temp"]);
|
34
34
|
})
|
35
35
|
})
|
36
|
+
```
|
37
|
+
|
38
|
+
---
|
39
|
+
|
40
|
+
# 追記
|
41
|
+
|
42
|
+
私が書くなら、オブジェクトをまとめてしまうかもですね。
|
43
|
+
|
44
|
+
```js
|
45
|
+
Promise.all(url.map(async ([endpoint, dataUrl]) => [endpoint,
|
46
|
+
await fetch(dataUrl, {
|
47
|
+
method: "GET",
|
48
|
+
})
|
49
|
+
.then(response => response.json())
|
50
|
+
]))
|
51
|
+
.then(x => console.log(Object.fromEntries(x).onecall.hourly[0].temp))
|
36
52
|
```
|
1
コメントを受けて追記
answer
CHANGED
@@ -12,4 +12,25 @@
|
|
12
12
|
console.log(endpoint, json["hourly"][0]["temp"]);
|
13
13
|
})
|
14
14
|
})
|
15
|
+
```
|
16
|
+
|
17
|
+
---
|
18
|
+
|
19
|
+
# コメントを受けて追記
|
20
|
+
|
21
|
+
こうですか?
|
22
|
+
|
23
|
+
```js
|
24
|
+
let url = [["forecast", url1], ["timemachine", url2], ["onecall", url3]];
|
25
|
+
|
26
|
+
url.forEach(function ([endpoint, dataUrl]) {
|
27
|
+
fetch(dataUrl, {
|
28
|
+
method: "GET",
|
29
|
+
})
|
30
|
+
.then(response => response.json())
|
31
|
+
.then(json => {
|
32
|
+
if (endpoint === "timemachine") console.log(json["hourly"][0]["temp"]);
|
33
|
+
if (endpoint === "onecall") console.log(json["hourly"][0]["temp"]);
|
34
|
+
})
|
35
|
+
})
|
15
36
|
```
|