Skip to main content
added 298 characters in body
Source Link
Nope
  • 22.4k
  • 8
  • 50
  • 73

You could check if the number has a remainder:

var data = 22;

if(data % 1 === 0){
   // yes it's an integer.
}

Mind you, if your input could also be text and you want to check first it is not, then you can check the type first:

var data = 22;

if(typeof data === 'number'){
     // yes it is numeric

    if(data % 1 === 0){
       // yes it's an integer.
    }
}

You could check if the number has a remainder:

var data = 22;

if(data % 1 === 0){
   // yes it's an integer.
}

You could check if the number has a remainder:

var data = 22;

if(data % 1 === 0){
   // yes it's an integer.
}

Mind you, if your input could also be text and you want to check first it is not, then you can check the type first:

var data = 22;

if(typeof data === 'number'){
     // yes it is numeric

    if(data % 1 === 0){
       // yes it's an integer.
    }
}
Source Link
Nope
  • 22.4k
  • 8
  • 50
  • 73

You could check if the number has a remainder:

var data = 22;

if(data % 1 === 0){
   // yes it's an integer.
}