Write your own js like trim method

  • 2020-03-26 21:21:52
  • OfStack

Since the trim method of JS is not supported in many browsers, we can use our own trim method here to deal with the need to cut out the empty strings at both ends of the string
String.prototype.trim = function () { 
return this .replace(/^ss*/, '' ).replace(/ss*$/, ''); 

Related articles: