How to use JavaScript String repeat()

Program to use JavaScript String repeat() method


let a = "Hello ";

let b = a.repeat(3);

console.log(b);

Output


Hello Hello Hello

Steps Description

  1. Declare two variables a and b
  2. Initialize two variable with value of string a = "Hello ".repeat(3) and b
  3. repeat() Method Whatever words or letters are written in the string, they can be repeated again and again.
  4. 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

  1. Declare two variables c and d
  2. Initialize two variable with value of string c = "Hello World \n".repeat(3) and d
  3. repeat() Method Whatever words or letters are written in the string, they can be repeated again and again.
  4. The value of d variable is displayed with the help of console.log inbuilt function