Home >Web Front-end >JS Tutorial >What is the JavaScript charAt() method?

What is the JavaScript charAt() method?

coldplay.xixi
coldplay.xixiOriginal
2020-11-13 14:36:3712377browse

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.

What is the JavaScript charAt() method?

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)

What is the JavaScript charAt() method?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn