如何检查NaN错误的值

how to check the value of an NaN error

本文关键字:NaN 错误 检查 何检查      更新时间:2023-09-26

嗨,所以我的logs.date打印出日志的实际日期,但当我推送它时在一个名为date的新数组中,它会在该数组的每个索引处给我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;
                }
            });

如果logs.dateundefined,则递增它将得到一个NaN值。

> undefined++
< NaN