编程篇(016)-写一个 function,清除字符串前后的空格(兼容所有的...
参考答案:
// 重写trim方法if (!String.prototype.trim) {String.prototype.trim = function() {return this.replace(/^\s+/, "").replace(/\s+$/, "");};}// test the functionvar str = " \t\n test string ".trim();console.log(str == "test string"); // true
评论
