Some times, a little RegExp is a beautiful thing…
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+$/, ""); }