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:
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:
function splitStr(str, seperator) { // Function to split string var string = str.split(seperator); console.log(string); } // Initialize string var str = "GeeksforGeeks/A/computer/science/portal"; var seperator = "/"; // Function call splitStr(str, seperator); |
Output:
[ 'GeeksforGeeks', 'A', 'computer', 'science', 'portal' ]
Recommended Posts:
- Nodejs | Automatic restart NodeJs server with nodemon
- 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
- Nodejs | GM quality() Function
- Nodejs | GM raise() Function
- Nodejs | GM resize() Function
- Nodejs | GM transparent() 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.

