美文网首页
实现String.prototype.trim函数的实现

实现String.prototype.trim函数的实现

作者: zhulichao | 来源:发表于2020-07-24 09:05 被阅读0次
       // 使用正则表达式
       String.prototype.trim = function() { 
           return this.replace(/(^\s*)|(\s*$)/g, ""); 
       } 
       String.prototype.trimLeft = function() { 
           return this.replace(/(^\s*)/g, ""); 
       } 
       String.prototype.trimRight = function() { 
           return this.replace(/(\s*$)/g, ""); 
       }
       ```
    

    相关文章

      网友评论

          本文标题:实现String.prototype.trim函数的实现

          本文链接:https://www.haomeiwen.com/subject/lnfjhktx.html