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
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


