根据日期重新构建数据结构

var arrays = [
{time:'2018-02-08',content:'修改了问题,原问题可以通过 sf 的历史版本功能查看。'},
{time:'2018-02-05',content:'修改了问题,原问题可以通过 sf 的历史版本功能查看。'},
{time:'2018-02-08',content:'修改了问题,原问题可以通过 sf 的历史版本功能查看。'},
{time:'2018-02-05',content:'修改了问题,原问题可以通过 sf 的历史版本功能查看。'},
{time:'2018-02-08',content:'修改了问题,原问题可以通过 sf 的历史版本功能查看。'},
];
function getNew() {
let newArray =[];
arrays.forEach(function (item,index) {
let idx;
let statusd = newArray.some(function (items,i) {
if(item.time == items.time){
idx=i;
return true;
}
});
if(statusd){
newArray[idx].text.push({content:item.content});
}else {
newArray.push({
time:item.time,
text:[{content:item.content}]
});
}
});
return newArray;
}
console.log(getNew());
posted @ 2018-02-08 15:57  编程让我快乐  阅读(153)  评论(0编辑  收藏  举报