The trim() method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
1 2 3 4 5 | var greeting = ' Hello world! I am Prem Tiwari '; console.log(greeting); console.log(greeting.trim()); |
Program Output
1 2 | > " Hello world! I am Prem Tiwari " > "Hello world! I am Prem Tiwari" |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.