Javascript String trim(str) method 2

Description

Javascript String trim(str) method 2


String.prototype.trim = function(str) {
 str = str.replace(/^\s+/,'');
 for( var i = str.length - 1 ; i >= 0 ; i--) {
  if(/\S/.test(str.charAt(i))) {
    str = str.substring(0,i+1);/*from   ww w .  j  a va  2  s .  c o  m*/
    break;
  }
 }
 return str;
};



PreviousNext

Related