While working with string in javascript sometimes we need to remove whitespace from the beginning and end of a string. Just do something like this:
String.prototype.trim=function(){ return this.replace(/^\s*|\s*$/g,”); } String.prototype.ltrim=function(){ return this.replace(/^\s*/g,”); } String.prototype.rtrim=function(){ return this.replace(/\s*$/g,”); }
How to use:
var myString = ‘ [...]