Program to use JavaScript String repeat() method
let a = "Hello ";
let b = a.repeat(3);
console.log(b);
Output
Hello Hello Hello
Steps Description
- Declare two variables
a
andb
- Initialize two variable with value of string
a = "Hello ".repeat(3)
andb
repeat()
Method Whatever words or letters are written in the string, they can be repeated again and again.- The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript String repeat() method
let c = "Hello World \n";
let d = c.repeat(3);
console.log(d);
Output
Hello World
Hello World
Hello World
Steps Description
- Declare two variables
c
andd
- Initialize two variable with value of string
c = "Hello World \n".repeat(3)
andd
repeat()
Method Whatever words or letters are written in the string, they can be repeated again and again.- The value of
d
variable is displayed with the help of console.log inbuilt function