多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 一、字符串重复 ``` String.prototype.repeat = function(n) { var str = ''; for(var i=0; i<n; i++) { str += this; } return str; } 'abc'.repeat(3); // abcabcabc ``` ## 二、去除字符串两边空格 ~~~ // 方式1 String.prototype.trim=function(){   return this.replace(/(^\s*)|(\s*$)/g, ""); } console.log(' hello '.trim()); // hello // 方式2 console.log(' hello '.replace(/^\s+|\s+$/g, '')); // hello ~~~ ## 三、去除规则字符串最后一个字符,以逗号为例 ~~~ var str = 'a,b,c,'; // 方式1 str = str.substr(0, str.lastIndexOf(',')); // a,b,c // 方式2 str.replace(/,$/, ''); // a,b,c ~~~