Custom Search
Logiclabz
  • Home
  • Javascript
  • Trim Function in Javascript using String.prototype.trim extension

Trim Function in Javascript using String.prototype.trim extension

To extend the String.prototype with the trim() function I use this line of code:

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); }
This is sample code how to use the trim() function:
var sExample = new String (" testing trim ")
alert(sExample.trim())



Leave a reply


Do you like this post?