无涯教程-String.prototype.repeat(count)函数

33 阅读1分钟

此函数将指定的字符串重复指定的次数。

String.prototype.repeat(count) - 语法

str.repeat(count)
  • count    -  字符串应重复的次数。

String.prototype.repeat(count) - 返回值

返回一个新的字符串。

String.prototype.repeat(count) - 示例

var myBook=new String("Perl"); 
console.log(myBook.repeat(2)); 

运行上面代码输出

PerlPerl 

参考链接

www.learnfk.com/es6/es6-str…