回答編集履歴
3
説明追記
test
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
ブロック内でconst宣言した変数はブロックから抜けると破棄されますよ。
|
2
|
+
最初に変数宣言するといいです。
|
2
3
|
|
3
4
|
```js
|
4
5
|
let planPoint;
|
2
変数名修正
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
他の方法:
|
15
15
|
|
16
16
|
```js
|
17
|
-
const
|
17
|
+
const planPoint = planList.map(plan => plan.plans).flat().find(plan => plan.id === '5')?.score;
|
18
18
|
console.log('point' , planPoint)
|
19
19
|
```
|
20
20
|
|
1
説明追記
test
CHANGED
@@ -1,9 +1,20 @@
|
|
1
|
+
ブロック内でconst宣言した変数はブロックから抜けると破棄されますよ。
|
2
|
+
|
1
3
|
```js
|
2
|
-
|
4
|
+
let planPoint;
|
3
|
-
|
5
|
+
planList.forEach(e1 => {
|
4
|
-
.flat()
|
5
|
-
|
6
|
+
const result = e1.plans.find(e2 => e2.id === '5');
|
7
|
+
if(result){
|
6
|
-
|
8
|
+
planPoint = result.score;
|
9
|
+
}
|
10
|
+
})
|
7
|
-
console.log(
|
11
|
+
console.log('point' , planPoint)
|
8
12
|
```
|
9
13
|
|
14
|
+
他の方法:
|
15
|
+
|
16
|
+
```js
|
17
|
+
const score = planList.map(plan => plan.plans).flat().find(plan => plan.id === '5')?.score;
|
18
|
+
console.log('point' , planPoint)
|
19
|
+
```
|
20
|
+
|