JavaScript substring length
This section illustrates you how to determine the length of substring in JavaScript.
You can see in the given example, we have defined a string and used the JavaScript method substring() in order to extract the substring from the defined string. Now, we have used the JavaScript property length that allows to retrieve the length of the substring.
Here is the code:
| <html> <h2>Get the length of Substring</h2> <script type="text/javascript"> var str = "Hello World"; var sub= str.substr(0,4); document.writeln("The substring is :"+ sub+"<br>"); document.writeln("The length of the substring is :"+ sub.length); </script> </html> |
Output will be displayed as:
Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


