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

How to use the charAt function

不言
Release: 2019-02-18 17:41:29
Original
7763 people have browsed it

str.charAt() in How to use the charAt function is used to return the character at a given string index. Let's take a look at the specific use of the charAt function.

How to use the charAt function

Let’s first take a look at the basic syntax of the charAt function

character = str.charAt(index)
Copy after login

The only parameter of the charAt function is the index in the string. Extract a single character from it. The range of this index is between 0 and length - 1, inclusive. If no index is specified, the first character of the string is returned, since 0 is the default index used for this function.

The function returns a single character located at the index specified as the function argument. If the index is out of range, this function returns an empty string.

Let’s take a look at the specific example of charAt function

The code is as follows

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
<script> 
function func() { 
    var str = &#39;How to use the charAt function is object oriented language&#39;; 
  
    var value = str.charAt(9); 
    document.write(value);   
} 
func(); 
</script>   
</body>
</html>
Copy after login

The output result is as follows: t

This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !

The above is the detailed content of How to use the charAt function. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!