如何用lodash将第一个数组转换为第二个?
来自:
var data = [
{'column':[1,1,1,1,1]},
{'column':[2,2,2,2,2]},
{'column':[3,3,3,3,3]},
]
致:
var data = [
{'column':[1,2,3]},
{'column':[1,2,3]},
{'column':[1,2,3]},
{'column':[1,2,3]},
{'column':[1,2,3]},
]
答案 0 :(得分:2)
你可以这样做:
var data = [
{'column':[1,1,1,1,1]},
{'column':[2,2,2,2,2]},
{'column':[3,3,3,3,3]},
];
var newData = _(data)
.map('column')
.unzip()
.map(function(col) {
return {'column': col};
})
.value();
console.log(newData);

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.11.2/lodash.min.js"></script>
&#13;