Home > Article > Web Front-end > What is the JavaScript charAt() method?
The JavaScript charAt() method can return the character at the specified position. The syntax is [stringObject.charAt(index)], where index represents the number at a certain position in the string, that is, the character at the bottom of the string. mark.
Definition and usage
charAt()
method returns the character at the specified position.
Please note that JavaScript does not have a character data type that is different from the string type, so the characters returned are strings of length 1.
Syntax
##stringObject.charAt(index)
Tips and comment
Comment: The index of the first character in the string is 0. If the parameter index is not between 0 and string.length, this method returns an empty string.Example
In the string "Hello world!", we will return the character at position 1:<script type="text/javascript"> var str="Hello world!" document.write(str.charAt(1)) </script>The output of the above code is:
e
Related free learning recommendations:JavaScript (video)
The above is the detailed content of What is the JavaScript charAt() method?. For more information, please follow other related articles on the PHP Chinese website!