Check if character is number?

前端 未结 22 764
误落风尘
误落风尘 2020-12-03 00:29

I need to check whether justPrices[i].substr(commapos+2,1).

The string is something like: \"blabla,120\"

In this case it would check whether \'0

22条回答
  •  旧时难觅i
    2020-12-03 00:57

    As far as I know, easiest way is just to multiply by 1:

    var character = ... ; // your character
    var isDigit = ! isNaN(character * 1);
    

    Multiplication by one makes a number from any numeric string (as you have only one character it will always be an integer from 0 to 9) and a NaN for any other string.

提交回复
热议问题