Node.js trim() function
The trim() function is a string function of Node.js which is used to remove white spaces from the string.
Syntax:
string.trim()
Parameter: This function does not accept any parameter.
Return Value: The function returns the string without white spaces.
The below programs demonstrate the working of trim() function:
Program 1:
javascript
function trim(str) { // Use trim() function let trimContent = str.trim(); console.log(trimContent); } // Initialize variable const str = " *w3wiki* " ; // Function call trim(str); |
Output:
*w3wiki*
Program 2:
javascript
function trim(str) { // Use trim() function const trimContent = str.trim(); console.log(trimContent); } // Initialize variable const str = " Welcome to w3wiki " ; // Function call trim(str); |
Output:
Welcome to w3wiki
Contact Us