Home > Web Front-end > JS Tutorial > body text

Introductory example of JavaScript charCodeAt method (used to obtain the Unicode encoding of the character at the specified position)_Basic knowledge

WBOY
Release: 2016-05-16 16:33:42
Original
1479 people have browsed it

JavaScript charCodeAt method

The charCodeAt method is used to obtain the Unicode encoding of the character at the specified position from the string. Its syntax is as follows:

Copy code The code is as follows:

str_object.charCodeAt( x )

Parameter description:

参数 说明
str_object 要操作的字符串(对象)
x 必需。表示位置的数字

Tip: String counting starts from 0.

charCodeAt method instance

Copy code The code is as follows:


Run this example, output:

Copy code The code is as follows:

98

If the parameter x is not between 0 and the maximum length of the string, this method will return NaN.

The charCodeAt method is very similar to the charAt method, except that the former returns the encoding of the character at the specified position, while the latter returns a character substring.

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