There was an error while loading. Please reload this page.
isWithinBounds returns true if the number n is a valid index for the given array arr, or false if it would be out of bounds.
true
n
arr
false
n: number
The potential index to test.
arr: Array<any>
The array to test against.
true if n is a valid index for arr, or false if it is not.
import { isWithinBounds } from '@revolutionarygamesco/common' const arr = [1, 2, 3] isWithinBounds(-1, arr) // false isWithinBounds(0, arr) // true isWithinBounds(2, arr) // true isWithinBounds(3, arr) // false isWithinBounds(1000, arr) // false