Skip to content
Related Articles

Related Articles

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

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 accepts any parameter.

Return Value: The function returns the string without white spaces.

Below programs demonstrate the working of trim() function:



Program 1:




function trim(str) {
      
    // Use trim() function
    var trimContent = str.trim();
      
    console.log(trimContent);
}
  
// Initialize variable
var str = "       *GeeksforGeeks*          ";
  
// Function call
trim(str);

Output:

*GeeksforGeeks*

Program 2:




function trim(str) {
      
    // Use trim() function
    var trimContent = str.trim();
      
    console.log(trimContent);
}
  
// Initialize variable
var str = "       Welcome to GeeksforGeeks          ";
  
// Function call
trim(str);    

Output:

Welcome to GeeksforGeeks

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 :