Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Javascript String Trimming Prototypes

DZone's Guide to

Javascript String Trimming Prototypes

·
Free Resource

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:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}