Checks if x is an integer and in the range for being a valid index for an array or string that has that length.
x
The value to check if it's a valid index.
The length of the array or string.
true if x is an integer and 0 <= x < length, false otherwise.
true
0 <= x < length
false
isInt
if length is not an integer.
length
if length is less than 0.
isIdx(0, 2) // => trueisIdx(1, 2) // => trueisIdx(2, 2) // => falseisIdx(-1, 2) // => falseisIdx(0.5, 2) // => false Copy
isIdx(0, 2) // => trueisIdx(1, 2) // => trueisIdx(2, 2) // => falseisIdx(-1, 2) // => falseisIdx(0.5, 2) // => false
Checks if
xis an integer and in the range for being a valid index for an array or string that has that length.