Now a days almost all browsers support trim function. e.g.
will result
"Leading and Trailing whitespace"
If the trim function is not supported you can use replace function with regular expression:
The regular expression modifier `g` is very important to be effectively removing the trailing white spaces.
" Leading and Trailing whitespace ".trim();
will result
"Leading and Trailing whitespace"
If the trim function is not supported you can use replace function with regular expression:
" Leading and Trailing whitespace ".replace(/^\s+|\s+$/g, '');
The regular expression modifier `g` is very important to be effectively removing the trailing white spaces.
No comments :
Post a Comment