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

What is the JavaScript charAt() method?

coldplay.xixi
Release: 2020-11-13 14:36:37
Original
12373 people have browsed it

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>
Copy after login

The output of the above code is:

e
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template