The Wayback Machine - https://web.archive.org/web/20240118174226/https://www.geeksforgeeks.org/node-js-split-function/
Open In App
Related Articles

Node.js split() function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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' ]
Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 30 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials