回答編集履歴
1
テキスト修正
test
CHANGED
@@ -19,3 +19,29 @@
|
|
19
19
|
```
|
20
20
|
|
21
21
|
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/GRZjoYK](https://codepen.io/jun68ykt/pen/GRZjoYK?editors=0012)
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
### 追記
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
配列やオブジェクトの操作で便利なライブラリ lodash の [_.zipWith](https://lodash.com/docs/#zipWith) を使うと、以下のように書けます。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
|
35
|
+
const ids = [1, 2, 3, 4];
|
36
|
+
|
37
|
+
const names = ['A', 'B', 'C', 'A'];
|
38
|
+
|
39
|
+
const addresses = ['a', 'b', 'c', 'a'];
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
const arr = _.zipWith(ids, names, addresses, (id, name, address) => ({ id, name, address }));
|
44
|
+
|
45
|
+
```
|
46
|
+
|
47
|
+
- **動作確認用サンプル:** [https://codepen.io/jun68ykt/pen/yLOaeQX](https://codepen.io/jun68ykt/pen/yLOaeQX?editors=0012)
|