Over a million developers have joined DZone.

Javascript String Trimming Prototypes

·

String.prototype.trim = function() {
 return this.replace(/^\s+|\s+$/g,"");
}

String.prototype.ltrim = function() {
 return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
 return this.replace(/\s+$/,"");
}

Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}