isArrayIndex
Utility for determining whether an input is a valid Array index.
Usage
Install the library:
npm install --save is-array-index
The module contains a single function, which takes a possible Array index as an argument and returns whether it is valid:
let isArrayIndex = ; ;// => true ;// => true ;// => false ;// => false
In some cases, it may make sense to allow for Array indices which exceed the maximum length of an array, but still satisfy the semantic requirements. This may be achieved by passing a second argument, a boolean
indicating whether to unrestrict the theoretical length of an array. See the Phonewords library for an example.
const MAX_ARRAY_LENGTH = Math - 1; ;// => false ;// => true ;// => true
Proxy Example
A Proxy
wrapped around an Array
might need to distinguish between array indexing and the accessing of additional properties.
let proxy = { if // execute additional processing return true; else return targetproperty; };