我有一個數組,我要計數和排序。我怎樣才能做到這一點?我的嘗試會導致無限循環。排序並將空值添加到數組如果需要
我想這個數組
[
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-05", timestamp: "2017-12-05 15:58:25", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-06", timestamp: "2017-12-06 10:13:12", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-06", timestamp: "2017-12-07 09:38:12", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-08", timestamp: "2017-12-08 09:35:25", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-11", timestamp: "2017-12-11 11:25:31", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-12", timestamp: "2017-12-12 15:05:17", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-13", timestamp: "2017-12-13 11:08:40", …}
{activityId: 201609011024550000, Employee_employeeId: 100, projectId: 300000000000000200, Date_date: "2017-12-15", timestamp: "2017-12-15 11:51:33", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-18", timestamp: "2017-12-18 11:04:56", …}
{activityId: 201609011024550000, Employee_employeeId: 4075, projectId: 300000000000000200, Date_date: "2017-12-15", timestamp: "2017-12-18 12:04:56", …}
]
看起來像基於此陣/排序上Date_date
(Date_date: 「2017年12月1日」 不存在,所以值是0, Date_date:「2017-12-06」存在兩次,因此值爲2)
[0,0,0,0...,1,2,0,1...]
好的,如果新建數組已創建。沒有jquery。
編輯: 對不起,這裏是循環不停止
for(var i = 0; i < a.length; i++){
for(var j = 0; j <= b.length; j++){
if(parseInt(a[i].Date_date.substring(8))-1==j){
var num = b[j];
b[j] = num+1;
}
else{
var num = b[j];
b[j] = num+0;
}
}
}
請更新這個職位與你已經嘗試過的代碼, – 31piy
添加您嘗試過的代碼,而不是直接要求的解決方案。另外,添加日期範圍。 –
看來你的代碼有問題。但是,除非我們有[可以重現問題的代碼或信息](// stackoverflow.com/help/mcve),否則我們無能爲力。否則,我們只是盲目猜測。 – Cerbrus