Home  >  Article  >  Web Front-end  >  JavaScript中length属性的使用方法_基础知识

JavaScript中length属性的使用方法_基础知识

WBOY
WBOYOriginal
2016-05-16 15:56:191279browse

 此属性返回字符串中的字符数。
语法

string.length

下面是参数的详细信息:

  •     A string

返回值:

返回字符串中的字符数。
例子:

<html>
<head>
<title>JavaScript String length Property</title>
</head>
<body>
<script type="text/javascript">
  var str = new String( "This is string" );
  document.write("str.length is:" + str.length); 
</script>
</body>
</html>

这将产生以下结果:

str.length is:14 

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