回答編集履歴
1
調整
answer
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
```javascript
|
2
|
-
const str= "1212121,
|
2
|
+
const str= "3434,1212121,43434,56757,7878787"
|
3
|
-
const
|
3
|
+
const check1=(keyword,str)=>RegExp(`(^|,)${keyword}(?=,|$)`).test(str);//正規表現
|
4
|
+
const check2=(keyword,str)=>str.split(",").includes(keyword);//配列
|
4
|
-
console.log(
|
5
|
+
console.log(check1("343434",str));
|
5
|
-
console.log(
|
6
|
+
console.log(check1("3434",str));
|
7
|
+
console.log(check2("343434",str));
|
8
|
+
console.log(check2("3434",str));
|
9
|
+
|
6
10
|
```
|