问题
希望能把当前的数组,根据相同的【日期】,放在一个数组里面;
let sourceData=[
{date:"2021-01-01",name:"LuckyJin"},
{date:"2021-01-01",name:"JinFed"},
{date:"2021-02-01",name:"olivivian"}
]
var dataTemp = []
var newData = []
sourceData.forEach( item =>{
dataTemp[item.date] = dataTemp[item.date] || [];
dataTemp[item.date].push(item);
})
console.log('格式一',dataTemp)
效果:
for (let key in dataTemp ) {
let obj = {}
obj.date = key
obj.list = dataTemp[key]
newData.push(obj)
}
console.log('格式二',newData);
效果: