回答編集履歴
6
a
test
CHANGED
@@ -39,3 +39,7 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
`selectedWeeks`が配列であると仮定するならば、`Array.prototype.includes()`が使えるので調べて見てください。[https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
なお、`String.prototype.includes()`も存在しているので、`selectedWeeks`が文字列の場合でも`includes`は使えます。
|
5
a
test
CHANGED
@@ -14,9 +14,9 @@
|
|
14
14
|
|
15
15
|
const todo = {};
|
16
16
|
|
17
|
-
todo.selectedWeeks.in
|
17
|
+
todo.selectedWeeks.indexOf('monday')
|
18
18
|
|
19
|
-
// => Uncaught TypeError: Cannot read property 'in
|
19
|
+
// => Uncaught TypeError: Cannot read property 'indexOf' of undefined
|
20
20
|
|
21
21
|
```
|
22
22
|
|
@@ -26,9 +26,9 @@
|
|
26
26
|
|
27
27
|
const todo = { selectedWeeks: undefined };
|
28
28
|
|
29
|
-
todo.selectedWeeks.in
|
29
|
+
todo.selectedWeeks.indexOf('monday')
|
30
30
|
|
31
|
-
// => Uncaught TypeError: Cannot read property 'in
|
31
|
+
// => Uncaught TypeError: Cannot read property 'indexOf' of undefined
|
32
32
|
|
33
33
|
```
|
34
34
|
|
4
a
test
CHANGED
@@ -31,3 +31,11 @@
|
|
31
31
|
// => Uncaught TypeError: Cannot read property 'includes' of undefined
|
32
32
|
|
33
33
|
```
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
> JSX上で「〜を含む」でindexOf()以外の方法を使う必要があるのでしょうか。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
`selectedWeeks`が配列であると仮定するならば、`Array.prototype.includes()`が使えるので調べて見てください。[https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
|
3
a
test
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
|
11
11
|
```
|
12
12
|
|
13
|
+
// 1
|
14
|
+
|
13
15
|
const todo = {};
|
14
16
|
|
15
17
|
todo.selectedWeeks.includes('monday')
|
@@ -17,3 +19,15 @@
|
|
17
19
|
// => Uncaught TypeError: Cannot read property 'includes' of undefined
|
18
20
|
|
19
21
|
```
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
// 2
|
26
|
+
|
27
|
+
const todo = { selectedWeeks: undefined };
|
28
|
+
|
29
|
+
todo.selectedWeeks.includes('monday')
|
30
|
+
|
31
|
+
// => Uncaught TypeError: Cannot read property 'includes' of undefined
|
32
|
+
|
33
|
+
```
|
2
a
test
CHANGED
@@ -3,3 +3,17 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
現状、`console.log(todo.selectedWeeks)`とすると、`undefined`になるはずです。
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
以下、簡易的なコードでの現象再現。
|
10
|
+
|
11
|
+
```
|
12
|
+
|
13
|
+
const todo = {};
|
14
|
+
|
15
|
+
todo.selectedWeeks.includes('monday')
|
16
|
+
|
17
|
+
// => Uncaught TypeError: Cannot read property 'includes' of undefined
|
18
|
+
|
19
|
+
```
|
1
a
test
CHANGED
@@ -2,4 +2,4 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
`console.log(todo.selectedWeeks)`とすると、`undefined`になるはずです。
|
5
|
+
現状、`console.log(todo.selectedWeeks)`とすると、`undefined`になるはずです。
|