回答編集履歴
3
4
answer
CHANGED
@@ -71,7 +71,7 @@
|
|
71
71
|
|
72
72
|
console.log(rest);
|
73
73
|
//[ { id: 3, name: 'yahoo', type: 'web', image: 'default.jpg' },
|
74
|
-
//{ id:
|
74
|
+
//{ id: 4, name: 'google', type: 'web', image: 'default.jpg' } ]
|
75
75
|
|
76
76
|
|
77
77
|
```
|
2
補足
answer
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
# サンプルコード
|
1
2
|
```
|
3
|
+
// 1つのオブジェクトを返すデモ関数
|
2
4
|
function findSiteById(id) {
|
3
5
|
|
4
6
|
return {
|
@@ -10,6 +12,7 @@
|
|
10
12
|
|
11
13
|
}
|
12
14
|
|
15
|
+
// 複数のオブジェクトを持つ配列を返すデモ関数
|
13
16
|
function findSitesByType(type) {
|
14
17
|
|
15
18
|
return [
|
@@ -49,7 +52,7 @@
|
|
49
52
|
|
50
53
|
}
|
51
54
|
|
52
|
-
|
55
|
+
//オブジェクトの分割代入
|
53
56
|
const { id, name, ...params } = findSiteById(1);
|
54
57
|
console.log(id); //1
|
55
58
|
console.log(name); //teratail
|
@@ -57,6 +60,7 @@
|
|
57
60
|
|
58
61
|
console.log('==========');
|
59
62
|
|
63
|
+
//配列の分割代入
|
60
64
|
const [a, b, ...rest] = findSitesByType('web');
|
61
65
|
|
62
66
|
console.log(a);
|
1
a
answer
CHANGED
@@ -51,17 +51,25 @@
|
|
51
51
|
|
52
52
|
|
53
53
|
const { id, name, ...params } = findSiteById(1);
|
54
|
-
console.log(id);
|
54
|
+
console.log(id); //1
|
55
|
-
console.log(name);
|
55
|
+
console.log(name); //teratail
|
56
|
-
console.log(params);
|
56
|
+
console.log(params); //{ type: 'web', image: 'default.jpg' }
|
57
57
|
|
58
58
|
console.log('==========');
|
59
59
|
|
60
60
|
const [a, b, ...rest] = findSitesByType('web');
|
61
|
+
|
61
62
|
console.log(a);
|
63
|
+
//{ id: 1, name: 'teratail', type: 'web', image: 'default.jpg' }
|
64
|
+
|
62
65
|
console.log(b);
|
63
|
-
|
66
|
+
//{ id: 2, name: 'facebook', type: 'web', image: 'default.jpg' }
|
64
67
|
|
68
|
+
console.log(rest);
|
69
|
+
//[ { id: 3, name: 'yahoo', type: 'web', image: 'default.jpg' },
|
70
|
+
//{ id: 3, name: 'google', type: 'web', image: 'default.jpg' } ]
|
71
|
+
|
72
|
+
|
65
73
|
```
|
66
74
|
|
67
75
|
[https://repl.it/repls/DifferentCompatibleLightweightprocess](https://repl.it/repls/DifferentCompatibleLightweightprocess)
|