JavaScript String substring() Method
You are Here:
JavaScript String substring() Method
The substring()
method returns the part of the string between the start and end indexes, or to the end of the string (if not specified).
substring() with start Index
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var str = "Hello there my old friend";
var result = str.substring(5);
document.write(result);
</script>
</body>
</html>
Syntax
str.substring(start, end)
Parameter Values
Value | Type | Explanation |
---|---|---|
start | Required | A index specifies the starting point of the extraction. |
end | optional | A index specifies the ending point of the extraction. If omitted, by default it extracts the rest of the string. |
Return Values
Value | Explanation |
---|---|
String | Returns a new string containing the specified part of the given string. |
Empty | Returns empty string, if start = end. |
substring() with start and end Indexes
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var str = "Hello there my old friend";
var result = str.substring(5, 18);
document.write(result);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.