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



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

Below programs demonstrate the working of trim() function:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

*GeeksforGeeks*

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Welcome to GeeksforGeeks


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.