7

Did a quick search for a seemingly trivial question but to no avail. I want to basically test whether a string element in an array within another array is a number or just characters. So I convert the string using parseInt and it either returns either the 'int' or 'NaN'.

However in an if statement if I use;

if (typeof (parseInt(a_data[j][i])) == "number") 
{
    console.log(parseInt(a_data[j][i]) + " is a number.") 
}

then after it prints out the ints it starts to print out "NaN is a number." I have gotten round this using;

if (!isNaN(parseInt(a_data[j][i])))
{
     console.log(parseInt(a_data[j][i]) + " is a number.")
}

but I am wondering why it thinking NaN is a number?

myol
  • 8,857
  • 19
  • 82
  • 143
  • 4
    Have a look at this question http://stackoverflow.com/questions/2801601/why-does-typeof-nan-return-number – ipr101 Jul 13 '11 at 12:14

0 Answers0