The substr() function is a string function of Node.js which is used to extract sub-string from the given string.
Syntax:
string.substr(index, length)
Parameters: This function accepts two parameters as mentioned above and described below:
- index: This parameter holds the starting index of the specified sub-string.
- length: This parameter holds the length of sub-string.
Return Value: The function returns the sub-string from given string.
Below programs demonstrate the working of substr() function:
Program 1:
function findsubstr(str) { var substring = str.substr(11, 13); console.log(substring); } var str = "Welcome to GeeksforGeeks"; findsubstr(str); |
chevron_right
filter_none
Output:
GeeksforGeeks
Program 2:
function findsubstr(str, index, length) { var substring = str.substr(index, length); console.log(substring); } var str = "Welcome to GeeksforGeeks"; var index = 11, length = 13; findsubstr(str, index, length); |
chevron_right
filter_none
Output:
GeeksforGeeks
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- PHP | substr() function
- JavaScript String substr() Method
- Difference between substr() and substring() in JavaScript
- TypeScript | String substr() Method
- Nodejs | GM charcoal() Function
- Nodejs | GM blur() Function
- Nodejs | GM sharpen() Function
- Nodejs | GM drawLine() Function
- Nodejs | GM drawArc() Function
- Nodejs | GM drawPolyline() Function
- Nodejs | GM drawBezier() Function
- Nodejs | GM drawCircle() Function
- Nodejs | GM drawEllipse() Function
- Nodejs | GM drawPolygon() Function
- Nodejs | GM drawRectangle() Function
- Nodejs | GM paint() Function
- Nodejs | GM orderedDither() Function
- Nodejs | GM roll() Function
- Nodejs | GM segment() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

