我有以下的方法 -计数出现基于小时在阵列
// Push the date values into dateArray
var dateArray = [];
$.each(dateHtml, function (i, el) {
dateArray.push(htmlDateValue);
}
});
然后排序最早日期 -
// sort array to have earliest date first
dateArray.sort(function (a, b) {
return new Date(b.date) - new Date(a.date);
});
离开我例如 -
dateArray =
["02/10/2015 00:00:07",
"02/10/2015 00:00:08",
"02/10/2015 01:00:03",
"02/10/2015 01:00:05",
"02/10/2015 02:00:14",
"03/10/2015 07:00:37"];
我已经创建了var arrOfCounts = [];
,我想填充每个h的计数值我们的存在于每个天中。
因此,例如上述的阵列的结果应该是 -
arrOfCounts =
[2, // 2 instances of values within the hour of 00:00:00 on the 02/10/2015
2, // 2 instances of values within the hour of 01:00:00 on the 02/10/2015
1, // 1 instances of values within the hour of 02:00:00 on the 02/10/2015
1]; // 1 instances of values within the hour of 07:00:00 on the 03/10/2015
所以我已经开始在dateArray
每个值的循环 -
$.each(dateArray, function (i, el) {
// Here I have to establish the value of count
arrOfCounts.push(count);
}
});
我怎么能做到这一点?
毫无疑问,开始与该处理日期/时间以及一个像样的图书馆! [moment.js](http://momentjs.com/)通常很受欢迎 – Jamiec
可能的重复http://stackoverflow.com/questions/16292349/count-occurrences-of-array-objects – guest271314