質問編集履歴
2
文法修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,10 +4,10 @@
|
|
4
4
|
|
5
5
|
```react
|
6
6
|
const fruits =[
|
7
|
-
{id: 0, title: apple, items: 3, condition: "good"},
|
7
|
+
{id: 0, title: "apple", items: 3, condition: "good"},
|
8
|
-
{id: 1, title: orange, items: 5, condition: "good"},
|
8
|
+
{id: 1, title: "orange", items: 5, condition: "good"},
|
9
|
-
{id: 2, title: kiwi, items: 1, condition: "
|
9
|
+
{id: 2, title: "kiwi", items: 1, condition: "good"},
|
10
|
-
{id: 3, title: cherry, items: 2, condition: "
|
10
|
+
{id: 3, title: "cherry", items: 2, condition: "Bad"},
|
11
11
|
]
|
12
12
|
```
|
13
13
|
上記の配列があったとして、`condition`の値を一括で全て`"Bad"`にしたい場合はどのようにすれば良いでしょうか。
|
@@ -17,20 +17,20 @@
|
|
17
17
|
|
18
18
|
```react
|
19
19
|
const disposal =[
|
20
|
-
{id: 0, title: apple, items: 3, condition: "Bad"},
|
20
|
+
{id: 0, title: "apple", items: 3, condition: "Bad"},
|
21
|
-
{id: 1, title: orange, items: 5, condition: "Bad"},
|
21
|
+
{id: 1, title: "orange", items: 5, condition: "Bad"},
|
22
|
-
{id: 2, title: kiwi, items: 1, condition: "Bad"},
|
22
|
+
{id: 2, title: "kiwi", items: 1, condition: "Bad"},
|
23
|
-
{id: 3, title: cherry, items: 2, condition: "Bad"},
|
23
|
+
{id: 3, title: "cherry", items: 2, condition: "Bad"},
|
24
24
|
]
|
25
25
|
```
|
26
26
|
|
27
27
|
###試したこと
|
28
28
|
```react
|
29
29
|
const fruits =[
|
30
|
-
{id: 0, title: apple, items: 3, condition: "good"},
|
30
|
+
{id: 0, title: "apple", items: 3, condition: "good"},
|
31
|
-
{id: 1, title: orange, items: 5, condition: "good"},
|
31
|
+
{id: 1, title: "orange", items: 5, condition: "good"},
|
32
|
-
{id: 2, title: kiwi, items: 1, condition: "Bad"},
|
32
|
+
{id: 2, title: "kiwi", items: 1, condition: "Bad"},
|
33
|
-
{id: 3, title: cherry, items: 2, condition: "good"},
|
33
|
+
{id: 3, title: "cherry", items: 2, condition: "good"},
|
34
34
|
]
|
35
35
|
console.log(fruits[0].title)
|
36
36
|
///apple と出力
|
@@ -40,7 +40,7 @@
|
|
40
40
|
id: [index],
|
41
41
|
title: fruits[index].title,
|
42
42
|
items: fruits[index].itemes,
|
43
|
-
condition: "Bad"
|
43
|
+
condition: "Bad",
|
44
44
|
};
|
45
45
|
});
|
46
46
|
|
1
試行したことを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,7 +24,32 @@
|
|
24
24
|
]
|
25
25
|
```
|
26
26
|
|
27
|
+
###試したこと
|
28
|
+
```react
|
29
|
+
const fruits =[
|
30
|
+
{id: 0, title: apple, items: 3, condition: "good"},
|
31
|
+
{id: 1, title: orange, items: 5, condition: "good"},
|
32
|
+
{id: 2, title: kiwi, items: 1, condition: "Bad"},
|
33
|
+
{id: 3, title: cherry, items: 2, condition: "good"},
|
34
|
+
]
|
35
|
+
console.log(fruits[0].title)
|
36
|
+
///apple と出力
|
27
37
|
|
38
|
+
const disposal = fruits.map((index) => {
|
39
|
+
return {
|
40
|
+
id: [index],
|
41
|
+
title: fruits[index].title,
|
42
|
+
items: fruits[index].itemes,
|
43
|
+
condition: "Bad";
|
44
|
+
};
|
45
|
+
});
|
46
|
+
|
47
|
+
console.log(disposal)
|
48
|
+
///出力失敗
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
|
28
53
|
### 補足情報
|
29
54
|
|
30
55
|
react初心者です。1、2ヶ月前からreactを触っていますが、純粋なJavaScriptは未経験です。すみません。
|