Trim functions for Javascript

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();
}

Please Share us:
Please rate this snippet

2 thoughts on “Trim functions for Javascript

Leave a Reply