JavaScript length 属性
![String 对象参考手册](https://image-10001577.image.myqcloud.com/upload/3/20170423/14929296332754.gif)
定义和用法
length 属性返回字符串的长度(字符数)。
语法
string.length
浏览器支持
所有主要浏览器都支持 length 属性
实例
返回字符串的字符数:
<script> var txt = "Hello World!"; document.write(txt.length); </script>
![String 对象参考手册](https://image-10001577.image.myqcloud.com/upload/3/20170423/14929296358268.gif)
length 属性返回字符串的长度(字符数)。
string.length
所有主要浏览器都支持 length 属性
返回字符串的字符数:
<script> var txt = "Hello World!"; document.write(txt.length); </script>