Skip to content

Function: isIntegerKey()

isIntegerKey(key): boolean

Checks if a key represents a valid integer index (like array indices). The key must be a string that represents a non-negative integer.

Parameters

key

unknown

The key to check

Returns

boolean

True if the key is a valid integer key

Example

typescript
console.log(isIntegerKey('0'))    // true
console.log(isIntegerKey('123'))  // true
console.log(isIntegerKey('-1'))   // false
console.log(isIntegerKey('1.5'))  // false
console.log(isIntegerKey('foo'))  // false
console.log(isIntegerKey('NaN'))  // false

Released under the MIT License.