charAt ( index: Number ) { String }

The String object's charAt() method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.

Parameters
Name Type Description
index Number

An integer between 0 and 1-less-than the length of the string. If the index cannot be converted to the integer or no index is provided, the default is 0, so the first character in of str is returned.

Returns

A string representing the character (exactly one UTF-16 code unit) at the specified index. If index is out of range, charAt() returns an empty string.

charCodeAt ( index: Number ) { Number }

The charCodeAt() method returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.

Parameters
Name Type Description
index Number

An integer greater than or equal to 0 and less than the length of the string. If index is not a number, it defaults to 0.

Returns

A number representing the UTF-16 code unit value of the character at the given index. If index is out of range, charCodeAt() returns NaN.