JavaScript String - length Property


Advertisements


Description

This property returns the number of characters in a string.

Syntax

Use the following syntax to find the length of a string −

string.length

Return Value

Returns the number of characters in the string.

Example

Try the following example.

<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>

Output

str.length is:14 

javascript_strings_object.htm

Advertisements