码迷,mamicode.com
首页 > 其他好文 > 详细

字符串处理

时间:2015-07-12 00:03:39      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

1.传入一个string类型的参数,然后将string的每个字符间加个空格返回

1    String.prototype.spacify = function(){
2        return this.split("").join(" ");
3    };
4    console.log("abc".spacify()); //a b c

2.将数组[1,2,3,4,5]变为[1,2,3,4,5,1,2,3,4,5]

1    Array.prototype.duplicator = function(){
2        for(var i = 0,len = this.length; i < len; i++){
3            this.push(this[i]);
4        }
5        return this;
6    };
7    
8    console.log([1,2,3,4,5].duplicator()); //[1,2,3,4,5,1,2,3,4,5]

3.输出参数,且加上规定的前缀

1    function log(){
2        var str = Array.prototype.slice.call(arguments);
3        str.unshift("(app)");
4        console.log.apply(console,str);
5    }
6    log("hello","world");  //(app) hello world

 

字符串处理

标签:

原文地址:http://www.cnblogs.com/webliu/p/4639517.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!