Home
> InDesign Scripts > QuickTip: Check if a number is between two numbers
QuickTip: Check if a number is between two numbers
In JavaScript I always miss one great feature from MySQL and that is operator between. It checks if a number is between two numbers you enter. So I decided to create small ‘Number’ prototype to achieve this. If a number is between is between then it returns true, and if not returns false. It’s perfect for using in ‘if()’ statements.
Number.prototype.between = function(first,last){
return (first < last ? this >= first && this <= last : this >= last && this <= first);
}
Usage:
var myNum = 315;
if(myNum.between(300,320)){ //returns true
//if true
}else{
//if false
}
Have fun!
Categories: InDesign Scripts
Javascript
IndiSnip on Twitter!
IndiSnip on Facebook!
Contact IndiSnip by e-mail!

Yeah, try this code to check if -5 is between 0 and -10 with this code. You’d be surprised
Wow, I was really surprised!
I updated the function
Thanks!
hi, this one really helped me, thanks!