回答編集履歴

3

4

2018/03/13 02:26

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -144,7 +144,7 @@
144
144
 
145
145
  //[ { id: 3, name: 'yahoo', type: 'web', image: 'default.jpg' },
146
146
 
147
- //{ id: 3, name: 'google', type: 'web', image: 'default.jpg' } ]
147
+ //{ id: 4, name: 'google', type: 'web', image: 'default.jpg' } ]
148
148
 
149
149
 
150
150
 

2

補足

2018/03/13 02:26

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -1,4 +1,8 @@
1
+ # サンプルコード
2
+
1
3
  ```
4
+
5
+ // 1つのオブジェクトを返すデモ関数
2
6
 
3
7
  function findSiteById(id) {
4
8
 
@@ -21,6 +25,8 @@
21
25
  }
22
26
 
23
27
 
28
+
29
+ // 複数のオブジェクトを持つ配列を返すデモ関数
24
30
 
25
31
  function findSitesByType(type) {
26
32
 
@@ -100,7 +106,7 @@
100
106
 
101
107
 
102
108
 
103
-
109
+ //オブジェクトの分割代入
104
110
 
105
111
  const { id, name, ...params } = findSiteById(1);
106
112
 
@@ -115,6 +121,8 @@
115
121
  console.log('==========');
116
122
 
117
123
 
124
+
125
+ //配列の分割代入
118
126
 
119
127
  const [a, b, ...rest] = findSitesByType('web');
120
128
 

1

a

2018/03/13 02:22

投稿

HayatoKamono
HayatoKamono

スコア2415

test CHANGED
@@ -104,11 +104,11 @@
104
104
 
105
105
  const { id, name, ...params } = findSiteById(1);
106
106
 
107
- console.log(id);
107
+ console.log(id); //1
108
108
 
109
- console.log(name);
109
+ console.log(name); //teratail
110
110
 
111
- console.log(params);
111
+ console.log(params); //{ type: 'web', image: 'default.jpg' }
112
112
 
113
113
 
114
114
 
@@ -118,11 +118,27 @@
118
118
 
119
119
  const [a, b, ...rest] = findSitesByType('web');
120
120
 
121
+
122
+
121
123
  console.log(a);
124
+
125
+ //{ id: 1, name: 'teratail', type: 'web', image: 'default.jpg' }
126
+
127
+
122
128
 
123
129
  console.log(b);
124
130
 
131
+ //{ id: 2, name: 'facebook', type: 'web', image: 'default.jpg' }
132
+
133
+
134
+
125
- console.log(rest);
135
+ console.log(rest);
136
+
137
+ //[ { id: 3, name: 'yahoo', type: 'web', image: 'default.jpg' },
138
+
139
+ //{ id: 3, name: 'google', type: 'web', image: 'default.jpg' } ]
140
+
141
+
126
142
 
127
143
 
128
144