Home >Web Front-end >JS Tutorial >How to use the length attribute
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.
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.
#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!