Home > Article > Web Front-end > Getting started with the charAt method of JavaScript string objects (used to obtain the character at the specified position)_Basic knowledge
JavaScript charAt method
The charAt method is used to get the character at the specified position from the string. Its syntax is as follows:
Parameter description:
参数 | 说明 |
---|---|
str_object | 要操作的字符串(对象) |
x | 必需。表示位置的数字 |
Tip: String counting starts from 0.
charAt method instance
Run this example, output:
Tip: If the parameter x is not between 0 and the maximum length of the string, this method will return an empty string.