JavaScript substring() Method
JavaScript String Object
Definition and Usage
The substring() method extracts the characters from a string, between two specified indices,
and returns the new sub string.
This method extracts the characters in a string between "from" and "to", not
including "to" itself.
Syntax
| string.substring(from, to) |
| Parameter |
Description |
| from |
Required. The index where to start the extraction. First character is at
index 0 |
| to |
Optional. The index where to stop the extraction. If omitted, it extracts the
rest of the string |
Browser Support

The substring() method is supported in all major browsers.
Example
Example
Extract characters from a string:
<script type="text/javascript">
var str="Hello world!";
document.write(str.substring(3)+"<br />");
document.write(str.substring(3,7));
</script>
|
The output of the code above will be:
Try it yourself »
|
JavaScript String Object
Start Creating a stunning, Flash website. It's easy and free!
Wix is a revolutionary web design tool that provides you with a free, simple,
drag & drop editing platform to create your own professional and beautiful website.
Over 2 Million users have created their website with Wix.
Now create yours!
 |
W3Schools' Online Certification Program
The perfect solution for professionals who need to balance work, family, and career building.
More than 4000 certificates already issued!
|
The HTML Certificate documents your knowledge of HTML, XHTML, and CSS.
The JavaScript Certificate documents your knowledge of JavaScript and HTML DOM.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
|