Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the length of a string in JavaScript?


To get the length of a string in JavaScript, use the length property. The length property returns the number of characters in a string.

Example

You can try to run the following code to learn how to get the length of a string

<html>
   <head>
      <title>JavaScript String length Property</title>
   </head>
 
   <body>
      <script>
         var str = new String( "Tutorialspoint Tutorials" );
         document.write("Length of string:" + str.length);
      </script>
   </body>
</html>