Skip to content
Related Articles
Open in App
Not now

Related Articles

Node.js split() function

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 14 Oct, 2021
Improve Article
Save Article

The split() function is a string function of Node.js which is used to split string into sub-strings. This function returns the output in array form.
Syntax: 
 

string.split( separator )

Parameters: This function accepts single parameter separator which holds the character to split the string.
Return Value: The function returns the splitted string and generates array as result.
Below programs demonstrate the working of split() function:
Program 1: 
 

javascript




function splitStr(str) {
      
    // Function to split string
    var string = str.split("*");
      
    console.log(string);
}
  
// Initialize string
var str = "Welcome*to*GeeksforGeeks";
  
// Function call
splitStr(str);    

Output: 
 

[ 'Welcome', 'to', 'GeeksforGeeks' ]

Program 2: 
 

javascript




function splitStr(str, separator) {
      
    // Function to split string
    var string = str.split(separator);
      
    console.log(string);
}
  
// Initialize string
var str = "GeeksforGeeks/A/computer/science/portal";
  
var separator = "/";
  
// Function call
splitStr(str, separator);

Output: 
 

[ 'GeeksforGeeks', 'A', 'computer', 'science', 'portal' ]

 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!