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

Related Articles

Node.js split() function

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

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

Syntax: 

string.split( separator )

Parameters: This function accepts a single parameter separator which holds the character to split the string.

Return Value: The function returns the split string and generates an array as result.

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

Example 1: 

javascript




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


Output: 

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

Example 2:

javascript




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


Output: 

[ 'GeeksforGeeks', 'A', 'computer', 'science', 'portal' ]
My Personal Notes arrow_drop_up
Last Updated : 30 Mar, 2023
Like Article
Save Article
Similar Reads
Related Tutorials