Check that variable is a number

前端 未结 10 1469
陌清茗
陌清茗 2020-12-29 20:38

How can I check that a variable is a number, either an integer or a string digit?

In PHP I could do:

if (is_int($var)) {
    echo \'$var is integer\'         


        
10条回答
  •  生来不讨喜
    2020-12-29 21:35

    You should use:

    if(Number.isInteger(variable))
       alert("It is an integer");
    else
       alert("It is not a integer");
    

    you can find the reference in: Number.isInteger()

提交回复
热议问题