alert(" taobao".trim()); // 输出 "taobao" alert(" taobao ".trim()); // 输出 "taobao"
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ""); };
String.prototype.trim = function(){ return this.replace(/^\s*|\s*$/g,""); }
String.prototype.trim = function () { return this.replace(/^\s+|\s+$/g, ''); } var test = ' after'; console.log(test.trim());
String.prototype.trim=function(){ var reg=/^\s*([a-zA-Z]{1,})\s*$/; return this.match(reg)[1]; } console.log("taobao ".trim());
String.prototype.trim=function(){ return this.replace(/^\s+|\s+$/g,''); }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题