嗨所以我的logs.date打印出日志的实际日期,但是当我按下它时 进入一个名为dates的新数组,它在该数组的每个索引处给出了Nan。这是我第一次使用forEach循环和indexOf函数。你们中的任何一个人都看错了吗?
这是我的代码:
theLogs.forEach(function(logs){
//if this line gets you 0 or higher it found it at that index, if you get -1 it was not found.
var index = dates.indexOf (logs.date);
if (index > -1){
//it was found so increment
dates[index]++;
}
else {
//it was not found so add a new entry in dates
dates.push(logs.date);
counters[counter] = 1;
}
});
答案 0 :(得分:0)
如果logs.date
为undefined
,那么递增它将为您提供NaN
值。
> undefined++
< NaN