Skip to content

at

The at() method returns the character at the specified index in a string, with support for negative indexes.

Interactive example

Syntax

Classic signature

typescript
function at(
	input: string,
	index: number
): string | undefined

Curried signature

typescript
function at<
	GenericInput extends string
>(
	index: number
): (input: GenericInput) => string | undefined

Parameters

  • input: The string from which to get the character.
  • index: The index of the character to return. Can be negative to count from the end (-1 for the last character).

Return value

A string representing the character at the specified index, or undefined if the index is out of bounds.

See also

  • charAt - Returns the character at an index (without negative index support)
  • indexOf - Finds the index of a substring

Sources

Released under the MIT license.