教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 Javascript重复拼写字符串 javascript string repeat的用法

Javascript重复拼写字符串 javascript string repeat的用法

发布时间:2015-02-21   编辑:jiaochengji.com
本文介绍下,在javascript中,使用repeat重复拼写字符串的方法,有需要的朋友参考下。

Javascript重复拼写字符串,可以有两个方法。

方法1:
 

复制代码 代码示例:
function repeat(s, n){ 
    var a = []; 
    while(a.length < n){ 
        a.push(s); 
    } 
    return a.join(''); 
}

方法2: 
 

复制代码 代码示例:
String.prototype.repeat = function( num ) 

    return new Array( num + 1 ).join( this ); 

您可能感兴趣的文章:
Javascript重复拼写字符串 javascript string repeat的用法
javascript字符串连接类代码一例
php str_repeat函数怎么用?
js数组转化为字符串示例
php与js有什么区别
未结束的字符串常量怎么解决
探讨js字符串数组拼接的性能问题
javascript arguments解析
python string是什么
php和js的区别是什么?

[关闭]
~ ~