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

How to use the length attribute

不言
Release: 2019-02-01 16:19:23
Original
7040 people have browsed it

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
Copy after login

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>
Copy after login

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!

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