Arrays.hasElementAt()
Syntax
function hasElementAt(array: readonly unknown[], index: number): boolean
Returns true if the given index refers to an actual element on the specified array.
Parameters | |
array
|
An array with any number of elements. |
index
|
The index to check. Can be any number. |
Example
import { Arrays } from 'potence';
const array = new Array(5);
array[0] = 1;
array[2] = undefined;
// -> [1, empty, undefined, empty, empty]
Arrays.hasElementAt(array, -1); // -> false
Arrays.hasElementAt(array, 0); // -> true
Arrays.hasElementAt(array, 1); // -> false
Arrays.hasElementAt(array, 2); // -> true
Remarks
Contrary to
Arrays.isInBounds()
,
this function checks whether there is actually an array element at the specified
index, instead of just checking whether the index is in-bounds.
Note that this function still returns true
if the element at that index
happens to be the value undefined
.