javascript
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 valueat String.repeat (<anonymous>)at <anonymous>:1:5 */翻譯自: https://www.includehelp.com/code-snippets/string-repeat-method-with-example-in-javascript.aspx
總結
以上是生活随笔為你收集整理的JavaScript中带示例的String repeat()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php怎么引用表单元素,表单元素:最全的
- 下一篇: python迭代器与生成器答案_史上最全