JavaScript中带示例的String repeat()方法

JavaScript | 字符串repeat()方法 (JavaScript | String repeat() Method)

The String.repeat() method in JavaScript is used to generate a string by repeating the calling string n number of times. n can be any integer from o to any possible number in JavaScript.

JavaScript中的String.repeat()方法用于通过将调用字符串重复n次来生成字符串。 n可以是从o到JavaScript中任何可能数字的任何整数。

Syntax:

句法:

    String.repeat(n);

Parameter(s):

参数:

The method accepts one parameter which is the number of times a number is repeated.

该方法接受一个参数,该参数是重复数字的次数。

Return value:

返回值:

The return type of this method is string which is the result of the repeating the strings.

此方法的返回类型是string ,这是重复字符串的结果。

Browser support: Chrome, Internet explorer, Mozilla, Safari, Opera mini.

浏览器支持: Chrome,Internet Explorer,Mozilla,Safari,Opera mini。

Example:

例:

str = "IncludeHelp"
//"IncludeHelp"
str.repeat(3)
//"IncludeHelpIncludeHelpIncludeHelp"
str.repeat(0)
//""
str.repeat(str.length)
//"IncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelpIncludeHelp"
str.repeat(-1)
/*
VM424:1 Uncaught RangeError: Invalid count value
    at String.repeat (<anonymous>)
    at <anonymous>:1:5
*/	


翻译自: https://www.includehelp.com/code-snippets/string-repeat-method-with-example-in-javascript.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值