Skip to content
Related Articles

Related Articles

Node.js | slice() function
  • Last Updated : 30 Aug, 2019

The slice() function is a string function of Node.js which is used to extract sub-string from a string.


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);
var str = "Welcome to GeeksforGeeks";



Program 2:

function findsubstr(str, start, end) {
    var index = str.slice(start, end);
var str = "Welcome to GeeksforGeeks";
var start = 0;
var end = 6;
findsubstr(str, start, end);



Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :