Node.js trim() function
Last Updated :
30 Mar, 2023
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) {
let trimContent = str.trim();
console.log(trimContent);
}
const str = " *GeeksforGeeks* " ;
trim(str);
|
Output:
*GeeksforGeeks*
Program 2:
javascript
function trim(str) {
const trimContent = str.trim();
console.log(trimContent);
}
const str = " Welcome to GeeksforGeeks " ;
trim(str);
|
Output:
Welcome to GeeksforGeeks
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...