var arr = [
{ id: 1, status: 1, endTime: "2020-08-26 09:24:13" },
{ id: 2, status: 1, endTime: "2020-08-20 09:24:13" },
{ id: 3, status: 2, endTime: "2020-08-20 09:24:13" },
{ id: 4, status: 3, endTime: "2020-08-20 09:24:13" },
{ id: 5, status: 3, endTime: "2020-08-20 09:24:13" }
]
// 转成以下数据
// var status1 = [
// { id: 1, status: 1 },
// { id: 2, status: 1 }
// ]
// var status2 = [
// { id: 3, status: 2 }
// ]
// var status3 = [
// { id: 4, status: 3 },
// { id: 5, status: 3 }
// ]
let arr1 = []
let date = new Date().getTime()
arr1 = arr.reduce((o, _) => {
_.endTime = (new Date(_.endTime).getTime() - date) / (24 * 60 * 60 * 1000)
_.endTime = parseInt(_.endTime)
o[_.status] ? o[_.status].push(_) : o[_.status] = [_]
return o
}, []).filter(a => !!a)
console.log(arr1)
console