In js, if you want to obtain a character at the specified position of a string, you can use the charAt () function to obtain the character. We only need to pass the index at the specified position into the charAt () function to obtain the result. This article describes the basic syntax of the charAt () function and its examples. For more information about the coders, see. The charAt method returns the characters at the specified index position.
Basic syntax
StrObj. charAt (index)
Parameter Introduction
Parameters |
Description |
Index |
Required. Returns the zero-based index of the expected characters. The valid value is the value between 0 and the string length minus 1. |
Description
The charAt method returns a character value at the specified index position. The index of the first character in the string is 0, the index of the second character is 1, and so on. If the index value exceeds the valid range, an empty string is returned.
Instance: