回答編集履歴

1

コメントを受けて追記

2018/01/11 04:09

投稿

Lhankor_Mhy
Lhankor_Mhy

スコア36115

test CHANGED
@@ -55,3 +55,81 @@
55
55
  ```
56
56
 
57
57
  「5つ以上用意したい」とのことですが、キーの名前はどのように決めますか?
58
+
59
+
60
+
61
+ ##### コメントを受けて追記
62
+
63
+ ```js
64
+
65
+ var str = "9920123A" , infoList = {} , lastIndex = -1;
66
+
67
+ while(true){
68
+
69
+ var x,y;
70
+
71
+ var nextIndex = str.indexOf("20" , lastIndex+1); //20を見つけたら
72
+
73
+ if(nextIndex == -1){
74
+
75
+ break; //whileループから抜ける
76
+
77
+ }else{
78
+
79
+ x = str.substr(nextIndex-2 , 2);
80
+
81
+ infoList.ID = +x;//格納
82
+
83
+ console.log("x=" + x);
84
+
85
+
86
+
87
+ y = str.substr(nextIndex+2 , 1);
88
+
89
+ infoList.値1 = +y;//格納
90
+
91
+ console.log("y=" + y);
92
+
93
+
94
+
95
+ z = str.substr(nextIndex+3 , 1);
96
+
97
+ infoList.値2 = +z;//格納
98
+
99
+ console.log("z=" + z);
100
+
101
+ lastIndex = nextIndex;
102
+
103
+
104
+
105
+ x = str.substr(nextIndex+4 , 1);
106
+
107
+ infoList.値3 = +x;//格納
108
+
109
+ console.log("x=" + x);
110
+
111
+ lastIndex = nextIndex;
112
+
113
+
114
+
115
+ x = str.substr(nextIndex+5 , 1);
116
+
117
+ infoList.値4 = +x;//格納
118
+
119
+ console.log("x=" + x);
120
+
121
+ lastIndex = nextIndex;
122
+
123
+ }
124
+
125
+ }
126
+
127
+
128
+
129
+ /*
130
+
131
+ ({ID:99, 値1:1, 値2:2, 値3:3, 値4:NaN})
132
+
133
+ */
134
+
135
+ ```