charAt

charAt

> Functions

Returns the character of the string string located at position position. The first character of the string is at position 0.

Parameters
Return
TypeScript

In JavaScript, s.charAt(index) returns the empty string "" out of bounds, where charAt in LeekScript returns null: test === "", not === null. Two related forms: s[index] gives undefined out of bounds, and s.at(index) accepts a negative index counted from the end — "abc".at(-1) is "c", while "abc".charAt(-1) is "" and "abc"[-1] is undefined.

Python

In Python, you index the string directly: s[index]. An out-of-bounds index raises an IndexError instead of returning null like charAt in LeekScript, and a negative index counts from the end — "abc"[-1] is "c", not an error. To never raise an error, take a one-character slice: "abc"[5:6] is "".

Examples

charAt("Bonjour", 3) // "j" charAt("Bonjour", 999) // null