str.charAt() in How to use the charAt function is used to return the character at a given string index. Let's take a look at the specific use of the charAt function.
Let’s first take a look at the basic syntax of the charAt function
character = str.charAt(index)
The only parameter of the charAt function is the index in the string. Extract a single character from it. The range of this index is between 0 and length - 1, inclusive. If no index is specified, the first character of the string is returned, since 0 is the default index used for this function.
The function returns a single character located at the index specified as the function argument. If the index is out of range, this function returns an empty string.
Let’s take a look at the specific example of charAt function
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var str = 'How to use the charAt function is object oriented language'; var value = str.charAt(9); document.write(value); } func(); </script> </body> </html>
The output result is as follows: t
This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !
The above is the detailed content of How to use the charAt function. For more information, please follow other related articles on the PHP Chinese website!