The slice() function is a string function of Node.js which is used to extract sub-string from a string.
Syntax:
string.slice( start, end )
Parameters: This function uses thress parameters as mentioned above and described below:
- string: It holds the string content. The substring is extracted from this string.
- start: This parameter holds the starting index of sub-string.
- end: This parameter holds the ending index od sub-string.
Return type: The function returns the substring.
The program below demonstrates the working of the function:
Program 1:
function findsubstr(str) { var index = str.slice(12, 25); console.log(index); } var str = "Welcome to GeeksforGeeks"; findsubstr(str); |
chevron_right
filter_none
Output:
GeeksforGeeks
Program 2:
function findsubstr(str, start, end) { var index = str.slice(start, end); console.log(index); } var str = "Welcome to GeeksforGeeks"; var start = 0; var end = 6; findsubstr(str, start, end); |
chevron_right
filter_none
Output:
Welcome
Recommended Posts:
- Nodejs lodash.slice() function
- Nodejs | Automatic restart NodeJs server with nodemon
- PHP | Ds\Sequence slice() Function
- PHP | Ds\Vector slice() Function
- PHP | Ds\Deque slice() Function
- PHP | Ds\Set slice() Function
- 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
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.

