Home  >  Article  >  Web Front-end  >  Getting started with the charAt method of JavaScript string objects (used to obtain the character at the specified position)_Basic knowledge

Getting started with the charAt method of JavaScript string objects (used to obtain the character at the specified position)_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:33:441836browse

JavaScript charAt method

The charAt method is used to get the character at the specified position from the string. Its syntax is as follows:

Copy code The code is as follows:

str_object.charAt( x )

Parameter description:

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

Tip: String counting starts from 0.

charAt method instance

Copy code The code is as follows:


Run this example, output:

Copy code The code is as follows:

b

Tip: If the parameter x is not between 0 and the maximum length of the string, this method will return an empty string.

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