Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js substr() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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 the sub-string.

Return Value: The function returns the sub-string from the given string. 

The below programs demonstrate the working of substr() function: 

Example 1: 

javascript




function findsubstr(str) {
    let substring = str.substr(11, 13);
    console.log(substring);
}
const str = "Welcome to GeeksforGeeks";
 
findsubstr(str);


Output:

GeeksforGeeks

Example 2: 

javascript




function findsubstr(str, index, length) {
    let substring = str.substr(index, length);
    console.log(substring);
}
 
const str = "Welcome to GeeksforGeeks";
const index = 11, length = 13;
 
findsubstr(str, index, length);


Output:

GeeksforGeeks
My Personal Notes arrow_drop_up
Last Updated : 30 Mar, 2023
Like Article
Save Article
Similar Reads
Related Tutorials