回答編集履歴

3

構造体

2017/11/20 14:56

投稿

think49
think49

スコア18156

test CHANGED
@@ -128,6 +128,16 @@
128
128
 
129
129
 
130
130
 
131
+ > また、今回使用しているものは構造体と呼んでよいのでしょうか?
132
+
133
+
134
+
135
+ JavaScriptに「構造体」は存在しません。
136
+
137
+ `new Info` は単純なオブジェクトですね。
138
+
139
+
140
+
131
141
  ### 更新履歴
132
142
 
133
143
 

2

改善案を追記

2017/11/20 14:56

投稿

think49
think49

スコア18156

test CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
 
4
4
 
5
+ **(2017/11/20 23:54 追記)**
6
+
7
+
8
+
9
+ 質問の編集を受けて、要件が理解できた為、改善案を追記しました。
10
+
11
+
12
+
5
- ### for 文
13
+ ### for 文 (訂正前)
6
14
 
7
15
 
8
16
 
@@ -40,7 +48,7 @@
40
48
 
41
49
 
42
50
 
43
- ### new Set()
51
+ ### new Set() (訂正前)
44
52
 
45
53
 
46
54
 
@@ -74,4 +82,58 @@
74
82
 
75
83
 
76
84
 
85
+ ### 改善案
86
+
87
+
88
+
89
+ ```JavaScript
90
+
91
+ function Info (x, y) {
92
+
93
+ this.x = +x;
94
+
95
+ this.y = +y;
96
+
97
+ }
98
+
99
+
100
+
101
+ var data = [10,20,30,10,40,50], infoList = [];
102
+
103
+
104
+
105
+ for (var i = 0, len = data.length, x, y; i < len; ++i) {
106
+
107
+ if (data[i] === 10) {
108
+
109
+ x = data[i + 1];
110
+
111
+ y = data[i + 2];
112
+
113
+ infoList.push(new Info(x, y));
114
+
115
+ console.log(x);
116
+
117
+ console.log(y);
118
+
119
+ }
120
+
121
+ }
122
+
123
+
124
+
125
+ console.log(JSON.stringify(infoList)); // [{"x":20,"y":30},{"x":40,"y":50}]
126
+
127
+ ```
128
+
129
+
130
+
131
+ ### 更新履歴
132
+
133
+
134
+
135
+ - 2017/11/20 23:54 改善案を追記
136
+
137
+
138
+
77
139
  Re: yu-kos さん

1

Array.prototype.includes

2017/11/20 14:55

投稿

think49
think49

スコア18156

test CHANGED
@@ -3,6 +3,10 @@
3
3
 
4
4
 
5
5
  ### for 文
6
+
7
+
8
+
9
+ - [Array.prototype.includes() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes)
6
10
 
7
11
 
8
12