Home >Web Front-end >JS Tutorial >How to use the length attribute

How to use the length attribute

不言
不言Original
2019-02-01 16:19:237065browse

The length attribute in How to use the length attribute is used to return the number of characters in a string, which is the length of the string. In the following article, we will briefly introduce the usage of the length attribute.

How to use the length attribute

Basic syntax of the length attribute

string.length

Note: The length of an empty string is 0.

Let’s take a look at Specific examples

The code is as follows

<!DOCTYPE html>
<html>
   <head>
      <title></title>
   </head>
   <body> 
<script type="text/javascript"> 
    var str = new String("php中文网"); 
    document.write("字符串长度为:"+str.length);  
</script> 
   </body>
</html>

The running effect on the browser is as follows: We can see the "php Chinese network" characters The length of the string is 6.

How to use the length attribute

#The application of the length attribute is very simple. This article ends here. For more exciting content, you can pay attention to other column tutorials on the PHP Chinese website.

The above is the detailed content of How to use the length attribute. 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
Previous article:How to use round methodNext article:How to use round method