This snippet will give you the Trim functions for Javascript.

Sample Javascript

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

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

String.prototype.trim = function () {
    return this.ltrim().rtrim();
}

2 thought on “Trim functions for Javascript”

Leave a Reply