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:
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.