How to trim a string in JavaScript

{0 Comments}

In latest IE browser has a inbuilt function to trim the string you only have to call trim () function.  And if you are using another version then you can use following trim syntax in the JavaScript which will help you to trim strings. 

 Javascript |  copy code |? 
1
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};
2

Leave a Comment

Your email address will not be published.