jty
    Preparing search index...

    Function isIdx

    • Checks if x is an integer and in the range for being a valid index for an array or string that has that length.

      Parameters

      • x: unknown

        The value to check if it's a valid index.

      • length: unknown

        The length of the array or string.

      Returns x is number

      true if x is an integer and 0 <= x < length, false otherwise.

      isInt

      if length is not an integer.

      if length is less than 0.

      isIdx(0, 2) // => true
      isIdx(1, 2) // => true
      isIdx(2, 2) // => false
      isIdx(-1, 2) // => false
      isIdx(0.5, 2) // => false