对这样的数据
[
{
"date": "2018",
"modified": 1516884840670,
"content": null
},
{
"date": "2016",
"modified": 1516884600059,
"content": null
},
{
"date": "2016",
"modified": 1516884359841,
"content": null
}, ...]
分组成
[{
year: "2018",
likes: [{
"date": "2018",
"modified": 1516884840670,
"content": null
}, {...}]]
使用 Lodash 可以这样操作
let groupedItems = _(list)
.groupBy(item => item.date)
.map((items, year) => {
return {
year: year,
likes: items
}
})
.reverse() // 为了反转数组排序
.value()