Home >Web Front-end >JS Tutorial >How to use the charAt function

How to use the charAt function

不言
不言Original
2019-02-18 17:41:297854browse

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)

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>

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!

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