JS根据时间内容分组代码

let newArr = [];
res.data.data.forEach((address, i) => {
let index = -1;
let newDates = Date.parse(new Date(address.created_at).toLocaleDateString());
console.log(newDates);
let alreadyExists = newArr.some((newAddress, j) => {
if (newDates === newAddress.created_at) {
index = j;
return true;
}
});
if (!alreadyExists) {
newArr.push({
created_at: newDates,
id:address.id,
location: [address.title]
});
} else {
newArr[index].location.push(address.title);
}
});
newArr.map((item,index)=>{
let date = new Date(item.created_at).toLocaleString();
let newDate = date.substring(0,10);
item.created_at = newDate;
});
posted @ 2017-12-08 16:15  编程让我快乐  阅读(521)  评论(0编辑  收藏  举报