Javascript examples for String:repeat
The repeat() method returns a new string with a specified number of copies.
string.repeat(count);
Parameter | Description |
---|---|
count | Required. The number of times the original string value should be repeated in the new string |
A String, a new string containing copies of the original string
The following code shows how to Make a new string by copying a string twice:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {/*from w ww .j ava2 s . c o m*/ var str = "Hello world!"; document.getElementById("demo").innerHTML = str.repeat(2); } </script> </body> </html>