How to trim a string in JavaScript


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 |? 
String.prototype.trim=function(){return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');};

Leave a Comment

Your email address will not be published.